- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
例如,asyncio.gather
具有签名 asyncio.gather(*coros_or_futures, loop=None, return_exceptions=False)
。
我可以传递特定循环或保留None
(并且将使用默认事件循环)。
为什么BaseEventLoop.run_in_executor
不以同样的方式定义,例如:asyncio.run_in_executor(executor,callback,*args,loop=None)
?
是否有一些重要原因将其放入BaseEventLoop
?
最佳答案
历史上run_in_executor
出现得很早,它是一个事件循环的方法。它模仿了twisted 在线程池中运行代码的方法。出现后,run_in_executor
从未改变。它是低级函数,接受回调,并且与接受回调的其他函数非常接近,而不是协程:call_soon()
、call_later()
、add_reader( )
等等,这些都是事件循环的方法。
asyncio.gather
在库开发大约一年之后才被邀请。它位于更高的抽象级别,与协程一起使用,并与其他与协程相关的函数(如 wait()
或 sleep()
)一起插入。
关于python - 为什么run_in_executor放在BaseEventLoop中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31192996/
我如何设置一个阻塞函数在执行器中运行,以一种结果无关紧要的方式,这样主线程不应该等待或被它减慢。 老实说,我不确定这是否是正确的解决方案,我想要的只是将某种类型的处理队列与主进程分开,这样它就不会阻止
我觉得 run_in_executor() asyncio的方法图书馆属于loop目的。 特别是,如果我选择以“通常”的方式在异步事件循环旁边运行第二个线程,会有什么不同,作者是 import thr
概览 我正在尝试并行化一个文本分类项目,该项目肯定需要很长时间才能完全串行运行。我已经尝试了这两种可能的变体,我相信它们的功能相似,并且对我在资源监视器中看到的每种结果很好奇。 第一个解决方案 我尝试
我有一个服务器应用程序,当客户请求时,我会安排一些工作,比如 def work(): time.sleep(5) fut = asyncio.get_event_loop().run_in_e
如何在使用 run_in_executor 调用的 run_long_thing() 函数中引发异常?看起来像是被吞噬了一样。我不需要阻塞代码中函数的结果。它基本上是一个即发即忘的功能,但如果有任何异
如何终止 loop.run_in_executor与 ProcessPoolExecutor优雅?启动程序后不久,发送 SIGINT (ctrl + c)。 def blocking_task():
全部! 我需要向 Web 服务发出大约 10,000 个请求,并且我希望得到 JSON 响应。由于请求是相互独立的,所以我想并行运行它们。我认为 aiohttp 可以帮助我解决这个问题。我编写了以下代
我想运行一个使用协程和多线程请求 URL 的服务。但是我无法将协程传递给执行器中的工作人员。有关此问题的最小示例,请参阅下面的代码: import time import asyncio import
我正在尝试在 concurrent.futures 的帮助下同时发送 POST 请求。由于某种原因,我无法设置自定义 header 。我要设置 授权 内容类型 这是我到目前为止所取得的进展。 impo
我正在使用 asyncio 来运行一段这样的阻塞代码: result = await loop.run_in_executor(None, long_running_function) 我的问题是:我
我正在尝试将参数传递给 run_in_executor,如下所示: loop.run_in_executor(None, update_contacts, data={ 'em
我正在试用 asyncio,并且必须将它与一些普通的多线程阻塞代码混合使用,因此我需要使用 run_in_exector 卸载执行。 asyncio docs warn that "most func
我对 Python Tornado 很陌生,并且一直在尝试启动一个新线程来运行一些 IO 阻塞代码,同时允许服务器继续处理新请求。我一直在阅读,但似乎仍然无法弄清楚这两个功能之间有什么区别? 例如调用
我编写了一个基准实用程序来批量查询 REST 端点。它通过三种方式实现: 依次使用请求库, 同时使用请求库,但使用 loop.run_in_executor() 包装每个请求, 同时使用 aiohtt
我指的是this repo是为了让mmaction2 grad-cam demo从短视频离线推理适配到长视频在线推理。脚本如下所示: 注意:为了使这个脚本可以很容易地重现,我注释掉了一些需要很多依赖的
问题重现环境: 操作系统:Windows 10(主机) 中央处理器:8 python :3.6.6 游戏版本:1.9.4 “构建器”:cx_Freeze 版本 5.1.1 问题未重现的环境: 操作系统
我正在用 Python 试验我的第一个小型爬虫,我想使用 asyncio 同时获取多个网站。我已经编写了一个与 aiohttp 一起使用的函数,但是由于 aiohttp.request() 不执行 j
我正在通过默认的 asyncio 事件循环运行函数 provision_ec2_node() thread executor .该函数采用一些参数,我通过 functools.partial() 将这
我是一名优秀的程序员,十分优秀!