parallel.futures和asyncio.futures有什么区别?

parallel.futures和asyncio.futures有什么区别?,第1张

parallel.futures和asyncio.futures有什么区别?

asyncio
文档涵盖了以下差异

asyncio.Future(*, loop=None)

此类与几乎兼容

concurrent.futures.Future

差异:

  • result()
    并且
    exception()
    不要接受超时参数,并且在未来还没有完成时引发异常。
  • add_done_callback()
    始终通过事件循环的调用注册到的回调
    call_soon_threadsafe()
  • 此类与包中的
    wait()
    as_completed()
    函数不兼容
    concurrent.futures


此类不是线程安全的。

基本上,如果您使用

ThreadPoolExecutor
ProcessPoolExecutor
,或者想
Future
直接将Direct用于基于线程或基于进程的并发,请使用
concurrent.futures.Future
。如果您正在使用
asyncio
,请使用
asyncio.Future



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5629836.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存