future

SCOOP – How to make workers wait for root worker before continuing

SCOOP – How to make workers wait for root worker before continuing Question: I am using SCOOP (and Python 3.6 – cannot be updated) in my work. I need all workers to perform a computation, then wait for the root node to execute a slow computation (the code in a if __name__ == ‘__main__’:), then …

Total answers: 1

Can't import annotations from __future__

Can't import annotations from __future__ Question: When running the statement from __future__ import annotations I get the following error: Traceback (most recent call last): File “/usr/lib/python3.5/py_compile.py”, line 125, in compile _optimize=optimize) File “<frozen importlib._bootstrap_external>”, line 735, in source_to_code File “<frozen importlib._bootstrap>”, line 222, in _call_with_frames_removed File “./prog.py”, line 1 from __future__ import annotations ^ SyntaxError: …

Total answers: 2

Differences between Futures in Python3 and Promises in ES6

Differences between Futures in Python3 and Promises in ES6 Question: Since Python 3.5, the keywords await and async are introduced to the language. Now, I’m more of a Python 2.7 person and I have been avoiding Python 3 for quite some time so asyncio is pretty new to me. From my understanding it seems like …

Total answers: 2

Combine awaitables like Promise.all

Combine awaitables like Promise.all Question: In asynchronous JavaScript, it is easy to run tasks in parallel and wait for all of them to complete using Promise.all: async function bar(i) { console.log(‘started’, i); await delay(1000); console.log(‘finished’, i); } async function foo() { await Promise.all([bar(1), bar(2)]); } // This works too: async function my_all(promises) { for (let …

Total answers: 4

Python: Wait on all of `concurrent.futures.ThreadPoolExecutor`'s futures

Python: Wait on all of `concurrent.futures.ThreadPoolExecutor`'s futures Question: I’ve given concurrent.futures.ThreadPoolExecutor a bunch of tasks, and I want to wait until they’re all completed before proceeding with the flow. How can I do that, without having to save all the futures and call wait on them? (I want an action on the executor.) Asked By: …

Total answers: 3

ProcessPoolExecutor from concurrent.futures way slower than multiprocessing.Pool

ProcessPoolExecutor from concurrent.futures way slower than multiprocessing.Pool Question: I was experimenting with the new shiny concurrent.futures module introduced in Python 3.2, and I’ve noticed that, almost with identical code, using the Pool from concurrent.futures is way slower than using multiprocessing.Pool. This is the version using multiprocessing: def hard_work(n): # Real hard work here pass if …

Total answers: 1

Python's `concurrent.futures`: Iterate on futures according to order of completion

Python's `concurrent.futures`: Iterate on futures according to order of completion Question: I want something similar to executor.map, except when I iterate over the results, I want to iterate over them according to the order of completion, e.g. the work item that was completed first should appear first in the iteration, etc. This is so the …

Total answers: 3

Pass multiple parameters to concurrent.futures.Executor.map?

Pass multiple parameters to concurrent.futures.Executor.map? Question: The concurrent.futures.Executor.map takes a variable number of iterables from which the function given is called. How should I call it if I have a generator that produces tuples that are normally unpacked in place? The following doesn’t work because each of the generated tuples is given as a different …

Total answers: 10