Python concurrent.futures.Future() Examples
The following are 30
code examples of concurrent.futures.Future().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
concurrent.futures
, or try the search function
.
Example #1
Source File: concurrent.py From tornado-zh with MIT License | 6 votes |
def set_exc_info(self, exc_info): """Sets the exception information of a ``Future.`` Preserves tracebacks on Python 2. .. versionadded:: 4.0 """ self._exc_info = exc_info self._log_traceback = True if not _GC_CYCLE_FINALIZERS: self._tb_logger = _TracebackLogger(exc_info) try: self._set_done() finally: # Activate the logger after all callbacks have had a # chance to call result() or exception(). if self._log_traceback and self._tb_logger is not None: self._tb_logger.activate() self._exc_info = exc_info
Example #2
Source File: concurrent.py From opendevops with GNU General Public License v3.0 | 6 votes |
def future_set_exception_unless_cancelled( future: "Union[futures.Future[_T], Future[_T]]", exc: BaseException ) -> None: """Set the given ``exc`` as the `Future`'s exception. If the Future is already canceled, logs the exception instead. If this logging is not desired, the caller should explicitly check the state of the Future and call ``Future.set_exception`` instead of this wrapper. Avoids ``asyncio.InvalidStateError`` when calling ``set_exception()`` on a cancelled `asyncio.Future`. .. versionadded:: 6.0 """ if not future.cancelled(): future.set_exception(exc) else: app_log.error("Exception after Future was cancelled", exc_info=exc)
Example #3
Source File: model.py From zulip-terminal with Apache License 2.0 | 6 votes |
def fetch_all_topics(self, workers: int) -> None: """ Distribute stream ids across threads in order to fetch topics concurrently. """ with ThreadPoolExecutor(max_workers=workers) as executor: list_of_streams = list(self.stream_dict.keys()) thread_objects = { i: executor.submit(self.get_topics_in_stream, list_of_streams[i::workers]) for i in range(workers) } # type: Dict[int, Future[str]] wait(thread_objects.values()) results = { str(name): self.exception_safe_result(thread_object) for name, thread_object in thread_objects.items() } # type: Dict[str, str] if any(results.values()): failures = ['fetch_topics[{}]'.format(name) for name, result in results.items() if result] raise ServerConnectionFailure(", ".join(failures))
Example #4
Source File: concurrent.py From opendevops with GNU General Public License v3.0 | 6 votes |
def future_set_exc_info( future: "Union[futures.Future[_T], Future[_T]]", exc_info: Tuple[ Optional[type], Optional[BaseException], Optional[types.TracebackType] ], ) -> None: """Set the given ``exc_info`` as the `Future`'s exception. Understands both `asyncio.Future` and the extensions in older versions of Tornado to enable better tracebacks on Python 2. .. versionadded:: 5.0 .. versionchanged:: 6.0 If the future is already cancelled, this function is a no-op. (previously ``asyncio.InvalidStateError`` would be raised) """ if exc_info[1] is None: raise Exception("future_set_exc_info called with no exception") future_set_exception_unless_cancelled(future, exc_info[1])
Example #5
Source File: concurrent.py From opendevops with GNU General Public License v3.0 | 6 votes |
def future_add_done_callback( # noqa: F811 future: "Union[futures.Future[_T], Future[_T]]", callback: Callable[..., None] ) -> None: """Arrange to call ``callback`` when ``future`` is complete. ``callback`` is invoked with one argument, the ``future``. If ``future`` is already done, ``callback`` is invoked immediately. This may differ from the behavior of ``Future.add_done_callback``, which makes no such guarantee. .. versionadded:: 5.0 """ if future.done(): callback(future) else: future.add_done_callback(callback)
Example #6
Source File: concurrent.py From tornado-zh with MIT License | 6 votes |
def set_exc_info(self, exc_info): """Sets the exception information of a ``Future.`` Preserves tracebacks on Python 2. .. versionadded:: 4.0 """ self._exc_info = exc_info self._log_traceback = True if not _GC_CYCLE_FINALIZERS: self._tb_logger = _TracebackLogger(exc_info) try: self._set_done() finally: # Activate the logger after all callbacks have had a # chance to call result() or exception(). if self._log_traceback and self._tb_logger is not None: self._tb_logger.activate() self._exc_info = exc_info
Example #7
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def unsubscribe_from_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "unsubscribe_from_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #8
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def set_proxy(self, proxyUrl): """ :rtype : Future """ args = list() args.append(proxyUrl) id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "set_proxy", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #9
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_hubs_structure(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_hubs_structure", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #10
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_subscribed_clients_to_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_subscribed_clients_to_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #11
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def is_client_connected(self, client_id): """ :rtype : Future """ args = list() args.append(client_id) id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "is_client_connected", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #12
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_subscribed_clients_to_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_subscribed_clients_to_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #13
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def unsubscribe_from_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "unsubscribe_from_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #14
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def write(self, port, data): """ :rtype : Future """ args = list() args.append(port) args.append(data) id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "write", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #15
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_config(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_config", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #16
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_libraries_path(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_libraries_path", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #17
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def restore_platformio_ini_file(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "restore_platformio_ini_file", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #18
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def set_id(self, client_id): """ :rtype : Future """ args = list() args.append(client_id) id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "set_id", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #19
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def subscribe_to_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "subscribe_to_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #20
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_subscribed_clients_to_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_subscribed_clients_to_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #21
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def forceClose(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "forceClose", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #22
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def subscribe_to_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "subscribe_to_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #23
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_subscribed_clients_to_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_subscribed_clients_to_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #24
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_all_buffered_records(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_all_buffered_records", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #25
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def unsubscribe_from_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "unsubscribe_from_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #26
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def subscribe_to_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "subscribe_to_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #27
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def set_lib_version(self, version): """ :rtype : Future """ args = list() args.append(version) id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "set_lib_version", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #28
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_version(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_version", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #29
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def get_subscribed_clients_to_hub(self, ): """ :rtype : Future """ args = list() id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "get_subscribed_clients_to_hub", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future
Example #30
Source File: hubs_api.py From web2board with GNU Lesser General Public License v3.0 | 5 votes |
def upload_hex_file(self, hex_file_path, board, port=None): """ :rtype : Future """ args = list() args.append(hex_file_path) args.append(board) args.append(port) id_ = self._get_next_message_id() body = {"hub": self.hub_name, "function": "upload_hex_file", "args": args, "ID": id_} future = self.ws_client.get_future(id_) send_return_obj = self.ws_client.send(self._serialize_object(body)) if isinstance(send_return_obj, Future): return send_return_obj return future