2024-04-25 21:26:16 发布
网友
要澄清此问题的原因:
使用同一名称的两个模块是令人困惑的。它们代表什么使它们与众不同?
一个能解决另一个不能解决的任务,反之亦然?
^{} documentation涵盖了这些差异:
class asyncio.Future(*, loop=None)This class is almost compatible with concurrent.futures.Future.Differences:result() and exception() do not take a timeout argument and raise an exception when the future isn’t done yet.Callbacks registered with add_done_callback() are always called via the event loop’s call_soon_threadsafe().This class is not compatible with the wait() and as_completed() functions in the concurrent.futures package.This class is not thread safe.
class asyncio.Future(*, loop=None)
asyncio.Future(*, loop=None)
This class is almost compatible with concurrent.futures.Future.
concurrent.futures.Future
Differences:
result()
exception()
add_done_callback()
call_soon_threadsafe()
wait()
as_completed()
concurrent.futures
This class is not thread safe.
基本上,如果您正在使用ThreadPoolExecutor或ProcessPoolExecutor,或者希望直接使用Future进行基于线程或基于进程的并发,请使用concurrent.futures.Future。如果您使用的是asyncio,请使用asyncio.Future。
ThreadPoolExecutor
ProcessPoolExecutor
Future
asyncio
asyncio.Future
从docs:
[asyncio provides a] Future class that mimics the one in the concurrent.futures module, but adapted for use with the event loop;
^{} documentation 涵盖了这些差异:
基本上,如果您正在使用
ThreadPoolExecutor
或ProcessPoolExecutor
,或者希望直接使用Future
进行基于线程或基于进程的并发,请使用concurrent.futures.Future
。如果您使用的是asyncio
,请使用asyncio.Future
。从docs:
相关问题 更多 >
编程相关推荐