- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 pyppeteer 和 quart 结合起来,但是由于启动浏览器需要很多时间,我宁愿全局处理它(使用异步锁),这似乎意味着我需要手动处理清理。这是我的最小代码示例:
#!/usr/bin/env python3
import asyncio
import atexit
import pyppeteer
from quart import Quart, Response, request
app = Quart(__name__)
browser = asyncio.get_event_loop().run_until_complete(pyppeteer.launch())
async def cleanup_async():
await browser.quit()
@atexit.register
def cleanup():
asyncio.get_event_loop().run_until_complete(cleanup_async())
[22:26:53] ➜ strokes git:(async_browser) ✗ % QUART_APP=/tmp/quart_cleanup.py timeout 10s quart run -h 0.0.0.0
Running on http://0.0.0.0:5000 (CTRL + C to quit)
Traceback (most recent call last):
File "/home/d33tah/virtualenv-py3/bin/quart", line 11, in <module>
sys.exit(main())
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/quart/cli.py", line 208, in main
cli.main(args=args, prog_name=name)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/quart/cli.py", line 152, in main
return super().main(*args, **kwargs)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/quart/cli.py", line 165, in run_command
use_reloader=debug,
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/quart/serving/__init__.py", line 146, in run_app
loop.run_until_complete(_observe_changes())
File "/usr/lib/python3.6/asyncio/base_events.py", line 454, in run_until_complete
self.run_forever()
File "/usr/lib/python3.6/asyncio/base_events.py", line 421, in run_forever
self._run_once()
File "/usr/lib/python3.6/asyncio/base_events.py", line 1371, in _run_once
event_list = self._selector.select(timeout)
File "/usr/lib/python3.6/selectors.py", line 445, in select
fd_event_list = self._epoll.poll(timeout, max_ev)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/launcher.py", line 146, in _close_process
asyncio.get_event_loop().run_until_complete(self.killChrome())
File "/usr/lib/python3.6/asyncio/coroutines.py", line 84, in debug_wrapper
return CoroWrapper(gen, None)
File "/usr/lib/python3.6/asyncio/coroutines.py", line 92, in __init__
self.gen = gen
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/launcher.py", line 146, in _close_process
asyncio.get_event_loop().run_until_complete(self.killChrome())
RuntimeError: coroutine wrapper <function debug_wrapper at 0x7f29878938c8> attempted to recursively wrap <code object killChrome at 0x7f2985e6edb0, file "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/launcher.py", line 188>
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/tmp/quart_cleanup.py", line 17, in cleanup
asyncio.get_event_loop().run_until_complete(cleanup_async())
File "/usr/lib/python3.6/asyncio/base_events.py", line 443, in run_until_complete
self._check_closed()
File "/usr/lib/python3.6/asyncio/base_events.py", line 357, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/launcher.py", line 146, in _close_process
asyncio.get_event_loop().run_until_complete(self.killChrome())
File "/usr/lib/python3.6/asyncio/base_events.py", line 443, in run_until_complete
self._check_closed()
File "/usr/lib/python3.6/asyncio/base_events.py", line 357, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
sys:1: RuntimeWarning: coroutine 'Launcher.killChrome' was never awaited
Exception ignored in: <object repr() failed>
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/coroutines.py", line 182, in __del__
msg = '%r was never yielded from' % self
File "/usr/lib/python3.6/asyncio/coroutines.py", line 99, in __repr__
coro_repr = _format_coroutine(self)
File "/usr/lib/python3.6/asyncio/coroutines.py", line 301, in _format_coroutine
func = coro.func
AttributeError: 'CoroWrapper' object has no attribute 'func'
Task was destroyed but it is pending!
task: <Task pending coro=<Connection._recv_loop() running at /home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/connection.py:54> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f2985bd5828>()] created at /usr/lib/python3.6/asyncio/base_events.py:275>>
Exception ignored in: <coroutine object Connection._recv_loop at 0x7f2985b39780>
Traceback (most recent call last):
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/connection.py", line 59, in _recv_loop
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/client.py", line 390, in __aexit__
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 370, in close
File "/usr/lib/python3.6/asyncio/tasks.py", line 342, in wait_for
File "/usr/lib/python3.6/asyncio/base_events.py", line 543, in call_later
File "/usr/lib/python3.6/asyncio/base_events.py", line 553, in call_at
File "/usr/lib/python3.6/asyncio/base_events.py", line 357, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending coro=<WebSocketCommonProtocol.transfer_data() running at /home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py:496> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f2985b5f258>()] created at /usr/lib/python3.6/asyncio/base_events.py:275> cb=[<TaskWakeupMethWrapper object at 0x7f2985bd5e58>(), _wait.<locals>._on_completion() at /usr/lib/python3.6/asyncio/tasks.py:380]>
Task was destroyed but it is pending!
task: <Task pending coro=<WebSocketCommonProtocol.close_connection() running at /home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py:711> wait_for=<Task pending coro=<WebSocketCommonProtocol.transfer_data() running at /home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py:496> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f2985b5f258>()] created at /usr/lib/python3.6/asyncio/base_events.py:275> cb=[<TaskWakeupMethWrapper object at 0x7f2985bd5e58>(), _wait.<locals>._on_completion() at /usr/lib/python3.6/asyncio/tasks.py:380]>>
Exception ignored in: <generator object WebSocketCommonProtocol.close_connection at 0x7f2985b39b48>
Traceback (most recent call last):
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 741, in close_connection
File "/usr/lib/python3.6/asyncio/streams.py", line 306, in close
File "/usr/lib/python3.6/asyncio/selector_events.py", line 622, in close
File "/usr/lib/python3.6/asyncio/base_events.py", line 574, in call_soon
File "/usr/lib/python3.6/asyncio/base_events.py", line 357, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
source_traceback: Object created at (most recent call last):
File "/home/d33tah/virtualenv-py3/bin/quart", line 11, in <module>
sys.exit(main())
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/quart/cli.py", line 208, in main
cli.main(args=args, prog_name=name)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/quart/cli.py", line 152, in main
return super().main(*args, **kwargs)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args[1:], **kwargs)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/quart/cli.py", line 165, in run_command
use_reloader=debug,
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/quart/serving/__init__.py", line 146, in run_app
loop.run_until_complete(_observe_changes())
File "/usr/lib/python3.6/asyncio/base_events.py", line 454, in run_until_complete
self.run_forever()
File "/usr/lib/python3.6/asyncio/base_events.py", line 421, in run_forever
self._run_once()
File "/usr/lib/python3.6/asyncio/base_events.py", line 1418, in _run_once
handle._run()
File "/usr/lib/python3.6/asyncio/events.py", line 127, in _run
self._callback(*self._args)
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/connection.py", line 54, in _recv_loop
resp = await self.connection.recv()
File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 305, in recv
self.messages.get(), loop=self.loop)
task: <Task pending coro=<Queue.get() running at /usr/lib/python3.6/asyncio/queues.py:167> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f2985b5f228>()] created at /usr/lib/python3.6/asyncio/base_events.py:275> cb=[_wait.<locals>._on_completion() at /usr/lib/python3.6/asyncio/tasks.py:380] created at /home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py:305>
Exception ignored in: <generator object Queue.get at 0x7f2985810c50>
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/queues.py", line 169, in get
File "/usr/lib/python3.6/asyncio/base_events.py", line 574, in call_soon
File "/usr/lib/python3.6/asyncio/base_events.py", line 357, in _check_closed
RuntimeError: Event loop is closed
最佳答案
我使用 @app.before_serving
解决了这个问题和 @app.after_serving
.
关于python-3.x - 运行时错误 : Event loop is closed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50556251/
此错误显然源于 xlsxwriter。我不确定它来自我的代码的哪一行,因为每次我尝试调试时,我的编辑器 Visual Studio 2019 都会崩溃。但是,在使用 VPN 和远程桌面连接时,我在笔记
我有一个用于原型(prototype)的游戏数据表。我在工作时生成数据,但当我离开并且我的机器进入休眠状态时,数据生成停止。这导致我的元素收藏出现很大差距。 我希望能够移动表格的 DateTimeCr
我正在使用wavesurfer在我的网页上显示歌曲波形。我正在使用以下代码 - function setupSongwaves(songJson) { var songwaveid = '#s
我是 JDBC 新手... Student类有Constructor、add()、update()和delete()等方法... 在构造函数中打开连接。下面代码中的 conn.close() 和 ps
考虑以下代码,它是许多 ChannelFactory 示例的典型代码: WSHttpBinding myBinding = new WSHttpBinding(); EndpointAddress m
我正在阅读 Java Data Access — JDBC、JNDI 和 JAXP,了解 Connection、PooledConnection 接口(interface)。据我了解, PooledC
我正在做我的第一个 android 学习教程,但遇到了标题描述的这个错误..这是我试图在 Eclipse 上做的应用程序,java,这是我的代码..(代码是自动生成的由项目) package com.
我正在使用 JPA、Hibernate、Jboss 和容器管理事务。当我尝试用数据保存我的大实体时,它会抛出以下异常。将我的实体视为图形模型。这个异常并不是每次都会抛出。 ERROR [org.jbo
我有 GWT 应用程序,它与 AdaptivePayment API 上的灯箱集成。 我无法使用提供的代码关闭取消/返回页面: dgFlow = top.dgFlow || top.opener.to
即使我已经实现了上述方法 close(),Eclipse 仍向我显示上述错误。 代码如下: public void update_project(View view) { EditText c
在我的网络应用程序中,我广泛使用了数据库。 我有一个抽象的 servlet,所有需要数据库连接的 servlet 都继承自它。该抽象 servlet 创建一个数据库连接,调用必须由继承 servlet
我在这里看到很多答案都说要使用 close() 来销毁套接字,但我使用的指南来自 msdn让我使用 closesocket()。我想知道是否存在差异,是否有理由使用其中一种。 在这两种情况下,我都看到
我在 python 中使用 with 语句( PEP 343 ) 时遇到了一些问题,以便在上下文之后自动管理资源清理。特别是,with 语句 始终假定资源清理方法是 .close()。 IE。在下面的
在本地连接上调用 RTCPeerConnection.close() 时,我希望远程连接接收到 closed connectionstatechange 事件。 相反,几秒钟后出现disconnect
我正在使用 netty 3.6.6。 有人可以解释以下两个代码之间的区别吗? channel.close(); channel.write(ChannelBuffers.EMPTY_BUFFER).a
WebSocket.readyState可以是CONNECTING、OPEN、CLOSING或CLOSED。 CLOSING 和 CLOSED 状态有什么区别?为什么区分这两种状态很有用?我可以将 C
想象一下,您在 Python 中打开了某个文件(无论是用于读取、写入还是其他)。我刚刚注意到,当您想关闭该文件时,您可以输入: somefile.close() 或者您可以输入: somefile.c
我在我的应用程序的各种类和线程中打开、访问、写入等数据库。我有一个数据库 self.run_params["db"] 我在整个应用程序中都使用它来访问。 问题 1:我是否应该在每次访问后关闭光标? 问
我正在尝试创建一个 vanilla JavaScript 模态,当从 HTML 文件(或 JS 文件)实例化它时,它具有由用户自定义的能力。但是,在处理关闭模式的 close() 函数时,不是一次关闭
所以这可能是一个菜鸟类型的问题,但这就是我想知道的。 假设我有两个屏幕,第一个屏幕是 idk,例如 Screen1。假设用户在 Screen1 上点击了OK,这会将他们带到Screen2。 我目前正在
我是一名优秀的程序员,十分优秀!