text stringlengths 0 828 |
|---|
typically triggered by the worker_init signal, however it must be called |
manually by codebases that are run only as task producers or from within |
a Python shell. |
"""""" |
success = True |
try: |
for func in SETUP_FUNCS: |
try: |
func(app) |
except Exception: |
success = False |
if throw: |
raise |
else: |
msg = ""Failed to run setup function %r(app)"" |
logger.exception(msg, func.__name__) |
finally: |
setattr(app, 'is_set_up', success)" |
1593,"def insert(self, item, priority): |
""""""Adds item to DEPQ with given priority by performing a binary |
search on the concurrently rotating deque. Amount rotated R of |
DEPQ of length n would be n <= R <= 3n/2. Performance: O(n)"""""" |
with self.lock: |
self_data = self.data |
rotate = self_data.rotate |
self_items = self.items |
maxlen = self._maxlen |
try: |
if priority <= self_data[-1][1]: |
self_data.append((item, priority)) |
elif priority > self_data[0][1]: |
self_data.appendleft((item, priority)) |
else: |
length = len(self_data) + 1 |
mid = length // 2 |
shift = 0 |
while True: |
if priority <= self_data[0][1]: |
rotate(-mid) |
shift += mid |
mid //= 2 |
if mid == 0: |
mid += 1 |
else: |
rotate(mid) |
shift -= mid |
mid //= 2 |
if mid == 0: |
mid += 1 |
if self_data[-1][1] >= priority > self_data[0][1]: |
self_data.appendleft((item, priority)) |
# When returning to original position, never shift |
# more than half length of DEPQ i.e. if length is |
# 100 and we rotated -75, rotate -25, not 75 |
if shift > length // 2: |
shift = length % shift |
rotate(-shift) |
else: |
rotate(shift) |
break |
try: |
self_items[item] += 1 |
except TypeError: |
self_items[repr(item)] += 1 |
except IndexError: |
self_data.append((item, priority)) |
try: |
self_items[item] = 1 |
except TypeError: |
self_items[repr(item)] = 1 |
if maxlen is not None and maxlen < len(self_data): |
self._poplast()" |
1594,"def addfirst(self, item, new_priority=None): |
""""""Adds item to DEPQ as highest priority. The default |
starting priority is 0, the default new priority is |
self.high(). Performance: O(1)"""""" |
with self.lock: |
self_data = self.data |
try: |
priority = self_data[0][1] |
if new_priority is not None: |
if new_priority < priority: |
raise ValueError('Priority must be >= ' |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.