text
stringlengths 0
828
|
|---|
#True if the condition is met.
|
timeout (number, None): The maximum number of seconds to wait.
|
# Returns
|
bool: #True if the condition was met, #False if not and a timeout ocurred.
|
""""""
|
with synchronized(obj):
|
if timeout is None:
|
while not cond(obj):
|
wait(obj)
|
else:
|
t_start = time.time()
|
while not cond(obj):
|
t_delta = time.time() - t_start
|
if t_delta >= timeout:
|
return False
|
wait(obj, timeout - t_delta)
|
return True"
|
434,"def as_completed(jobs):
|
''' Generator function that yields the jobs in order of their
|
completion. Attaches a new listener to each job. '''
|
jobs = tuple(jobs)
|
event = threading.Event()
|
callback = lambda f, ev: event.set()
|
[job.add_listener(Job.SUCCESS, callback, once=True) for job in jobs]
|
[job.add_listener(Job.ERROR, callback, once=True) for job in jobs]
|
while jobs:
|
event.wait()
|
event.clear()
|
jobs, finished = split_list_by(jobs, lambda x: x.finished)
|
for job in finished:
|
yield job"
|
435,"def split_list_by(lst, key):
|
""""""
|
Splits a list by the callable *key* where a negative result will cause the
|
item to be put in the first list and a positive into the second list.
|
""""""
|
first, second = [], []
|
for item in lst:
|
if key(item):
|
second.append(item)
|
else:
|
first.append(item)
|
return (first, second)"
|
436,"def reraise(tpe, value, tb=None):
|
"" Reraise an exception from an exception info tuple. ""
|
Py3 = (sys.version_info[0] == 3)
|
if value is None:
|
value = tpe()
|
if Py3:
|
if value.__traceback__ is not tb:
|
raise value.with_traceback(tb)
|
raise value
|
else:
|
exec('raise tpe, value, tb')"
|
437,"def result(self):
|
""""""
|
The result of the jobs execution. Accessing this property while the job is
|
pending or running will raise #InvalidState. If an exception occured during
|
the jobs execution, it will be raised.
|
# Raises
|
InvalidState: If the job is not in state #FINISHED.
|
Cancelled: If the job was cancelled.
|
any: If an exception ocurred during the job's execution.
|
""""""
|
if self.__cancelled:
|
raise Job.Cancelled
|
elif self.__state in (Job.PENDING, Job.RUNNING):
|
raise Job.InvalidState('job is {0}'.format(self.__state))
|
elif self.__state == Job.ERROR:
|
reraise(*self.__exception)
|
elif self.__state == Job.SUCCESS:
|
return self.__result
|
else:
|
raise RuntimeError('invalid job state {0!r}'.format(self.__state))"
|
438,"def exception(self):
|
""""""
|
The exception that occured while the job executed. The value is #None if
|
no exception occurred.
|
# Raises
|
InvalidState: If the job is #PENDING or #RUNNING.
|
""""""
|
if self.__state in (Job.PENDING, Job.RUNNING):
|
raise self.InvalidState('job is {0}'.format(self.__state))
|
elif self.__state == Job.ERROR:
|
assert self.__exception is not None
|
return self.__exception
|
elif self.__state in (Job.RUNNING, Job.SUCCESS, Job.CANCELLED):
|
assert self.__exception is None
|
return None
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.