text
stringlengths
0
828
self._result = result
self._completed = True
callbacks = self._prepare_done_callbacks()
callbacks()"
1329,"def set_exception(self, exc_info):
""""""
This method allows you to set an exception in the future without requring
that exception to be raised from the futures worker. This method can be
called on an unbound future.
:param exc_info: Either an exception info tuple or an exception value.
In the latter case, the traceback will be automatically generated
from the parent frame.
:raise RuntimeError: If the future is already enqueued.
""""""
if not isinstance(exc_info, tuple):
if not isinstance(exc_info, BaseException):
raise TypeError('expected BaseException instance')
try:
# TODO: Filld the traceback so it appears as if the exception
# was actually raised by the caller? (Not sure if possible)
raise exc_info
except:
exc_info = sys.exc_info()
exc_info = (exc_info[0], exc_info[1], exc_info[2])
with self._lock:
if self._enqueued:
raise RuntimeError('can not set exception of enqueued Future')
self._exc_info = exc_info
self._completed = True
callbacks = self._prepare_done_callbacks()
callbacks()"
1330,"def wait(self, timeout=None, do_raise=False):
""""""
Wait for the future to complete. If *timeout* is specified, it must be a
floating point number representing the maximum number of seconds to wait.
:param timeout: The maximum number of seconds to wait for the future
to complete.
:param do_raise: Raise :class:`Timeout` when a timeout occurred.
:raise Timeout: If a timeout occurred and *do_raise* was True.
:return: :const:`True` if the future completed, :const:`False` if a
timeout occurred and *do_raise* was set to False.
""""""
if timeout is not None:
timeout = float(timeout)
start = time.clock()
with self._lock:
while not self._completed and not self._cancelled:
if timeout is not None:
time_left = timeout - (time.clock() - start)
else:
time_left = None
if time_left is not None and time_left <= 0.0:
if do_raise:
raise self.Timeout()
else:
return False
self._lock.wait(time_left)
return True"
1331,"def enqueue(self, future):
""""""
Enqueue a future to be processed by one of the threads in the pool.
The future must be bound to a worker and not have been started yet.
""""""
future.enqueue()
with self._lock:
if self._shutdown:
raise RuntimeError('ThreadPool has been shut down and can no '
'longer accept futures.')
self._queue.append(future)
if len(self._running) == len(self._workers):
self._new_worker()
self._lock.notify_all()"
1332,"def submit(self, __fun, *args, **kwargs):
""""""
Creates a new future and enqueues it. Returns the future.
""""""
future = Future().bind(__fun, *args, **kwargs)
self.enqueue(future)
return future"
1333,"def cancel(self, cancel_running=True, mark_completed_as_cancelled=False):
""""""
Cancel all futures queued in the pool. If *cancel_running* is True,
futures that are currently running in the pool are cancelled as well.
""""""
with self._lock:
for future in self._queue:
future.cancel(mark_completed_as_cancelled)
if cancel_running:
for future in self._running:
future.cancel(mark_completed_as_cancelled)
self._queue.clear()"