text stringlengths 0 828 |
|---|
Execute the future in a new thread or in the current thread as specified |
by the *as_thread* parameter. |
:param as_thread: Execute the future in a new, separate thread. If this |
is set to :const:`False`, the future will be executed in the calling |
thread. |
"""""" |
with self._lock: |
if as_thread: |
self.enqueue() # Validate future state |
if self._cancelled: |
return |
self._running = True |
if as_thread: |
self._thread = threading.Thread(target=self._run) |
self._thread.start() |
return self |
self._run()" |
1325,"def result(self, timeout=None, do_raise=True): |
"""""" |
Retrieve the result of the future, waiting for it to complete or at |
max *timeout* seconds. |
:param timeout: The number of maximum seconds to wait for the result. |
:param do_raise: Set to False to prevent any of the exceptions below |
to be raised and return :const:`None` instead. |
:raise Cancelled: If the future has been cancelled. |
:raise Timeout: If the *timeout* has been exceeded. |
:raise BaseException: Anything the worker has raised. |
:return: Whatever the worker bound to the future returned. |
"""""" |
with self._lock: |
self.wait(timeout, do_raise=do_raise) |
if self._exc_info: |
if not do_raise: |
return None |
# Its more important to re-raise the exception from the worker. |
self._exc_retrieved = True |
reraise(*self._exc_info) |
if self._cancelled: |
if not do_raise: |
return None |
raise self.Cancelled() |
return self._result" |
1326,"def exception(self, timeout=None, do_raise=True): |
"""""" |
Returns the exception value by the future's worker or :const:`None`. |
:param timeout: |
:param do_raise: |
:param Cancelled: |
:param Timeout: |
:return: :const:`None` or an exception value. |
"""""" |
with self._lock: |
self.wait(timeout, do_raise=do_raise) |
if not self._exc_info: |
return None |
self._exc_retrieved = True |
if self._cancelled: |
raise self.Cancelled() |
return self._exc_info[1]" |
1327,"def cancel(self, mark_completed_as_cancelled=False): |
"""""" |
Cancel the future. If the future has not been started yet, it will never |
start running. If the future is already running, it will run until the |
worker function exists. The worker function can check if the future has |
been cancelled using the :meth:`cancelled` method. |
If the future has already been completed, it will not be marked as |
cancelled unless you set *mark_completed_as_cancelled* to :const:`True`. |
:param mark_completed_as_cancelled: If this is :const:`True` and the |
future has already completed, it will be marked as cancelled anyway. |
"""""" |
with self._lock: |
if not self._completed or mark_completed_as_cancelled: |
self._cancelled = True |
callbacks = self._prepare_done_callbacks() |
callbacks()" |
1328,"def set_result(self, result): |
"""""" |
Allows you to set the result of the future without requiring the future |
to actually be executed. This can be used if the result is available |
before the future is run, allowing you to keep the future as the interface |
for retrieving the result data. |
:param result: The result of the future. |
:raise RuntimeError: If the future is already enqueued. |
"""""" |
with self._lock: |
if self._enqueued: |
raise RuntimeError('can not set result of enqueued Future') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.