The two classes are great abstractions for concurrent programming, so it's a little confusing that they do not support the same API.
In particular, according to docs :
asyncio.Futurealmost compatible with concurrent.futures.Future.Differences:result()and exception()they don’t accept the timeout argument and throw an exception when the future is not yet fulfilled.Callbacks registered with add_done_callback()are always called through an event loop call_soon_threadsafe().This class is not compatible with the functions wait()and as_completed()in the package concurrent.futures.
asyncio.Futurealmost compatible with concurrent.futures.Future.
asyncio.Future
concurrent.futures.Future
Differences:
result()
exception()
add_done_callback()
call_soon_threadsafe()
wait()
as_completed()
concurrent.futures
The above list is actually incomplete, there are a few more differences:
running() missing methodresult()and exception()can raise InvalidStateErrorif too early
running()
InvalidStateError
- , , ?
, add_done_callback()? , - , , ?
, ( ) , , . , - , . , , , , .
concurrency , , , , . , , .
, , , , ? , , . , , , , . , , , . , .
, , . asyncio concurrent.futures, .
add_done_callbacks , . , . , , . , . .
add_done_callbacks
concurrent.futures.Future , Executor.
asyncio.Future , coroutines, , / . "" , , : , - /.
( threading/asyncio, Lock, Event, Semaphore ..) , concurrency / .
Lock
Event
Semaphore
, , , : asyncio , threading concurrent.futures. , concurrent.futures.Future asyncio API.
asyncio
threading
" "? , , , : asyncio threading , , asyncio/non-asyncio (. async/await).
async
await
, , , , : concurrency ( ).
Source: https://habr.com/ru/post/1017122/More articles:Git Hook Doesn't Work - gitConfigure Visual Studio to use Git.exe installed by the system - gitC - emulate "mutable" from C ++ - cТочки останова и отладочные операторы открывают "только встроенный контент для чтения" - debuggingHow to use InfiniBand network with Dask? - pythonIs the application definition function determinate in SML? - smlScala / Spark Version Compatibility - scalaThe strangest VBA question I have ever seen (VBASigned Possible Boolean Error) - vbatool: replace = android: значение для элемента в AndroidManisfest.xml: 25: 5-17: 34 для переопределения - javaHow to display the clear button on the left side of a UITextField? - iosAll Articles