默认执行器 asyncio

22
根据文档,当向run_in_executor传递None时,将使用默认执行器:

awaitable loop.run_in_executor(executor, func, *args) 安排让 func 在指定的执行器中被调用。

executor参数应该是concurrent.futures.Executor实例。 如果executor为None,则使用默认执行器。

我的问题是,asyncio的默认执行器是什么?
2个回答

17
我的问题是,asyncio的默认执行器是什么?
截至撰写本文(2020年2月,Python 3.9 alpha),它是一个concurrent.futures.ThreadPoolExecutor,具有默认设置
以前,可以调用set_default_executor来使用不同类型的执行器,但自Python 3.8起,它保证ThreadPoolExecutor。但是,其确切的设置未记录在文档中,因此它们可能会在未来的Python版本中发生变化。例如,在Python 3.10中,它设置了thread_name_prefix属性

请注意,默认设置取决于Python版本(https://docs.python.org/3/library/concurrent.futures.html?highlight=threadpoolexecutor#concurrent.futures.ThreadPoolExecutor),特别是_max_workers_。 - Eric Smith

5

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接