1

Consider the following code:

import asyncio
import pyppeteer

async def hi():
    ret = await pyppeteer.launch()
    await asyncio.sleep(10)
    return ret

browser = asyncio.get_event_loop().run_until_complete(hi())

If I run it, then hit Ctrl+C after a few, but less than 10 seconds, I get a few error messages and what seems to be an infinite loop:

Traceback (most recent call last):
  File "/tmp/a.py", line 10, in <module>
    browser = asyncio.get_event_loop().run_until_complete(hi())
  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 1390, 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 "/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 454, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.6/asyncio/base_events.py", line 408, in run_forever
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
Task exception was never retrieved
future: <Task finished coro=<Connection._async_send() done, defined at /home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/connection.py:61> exception=ConnectionClosed('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)>
Traceback (most recent call last):
  File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 669, in write_frame
    yield from self.writer.drain()
  File "/usr/lib/python3.6/asyncio/streams.py", line 333, in drain
    yield from self._protocol._drain_helper()
  File "/usr/lib/python3.6/asyncio/streams.py", line 204, in _drain_helper
    raise ConnectionResetError('Connection lost')
ConnectionResetError: Connection lost

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/connection.py", line 64, in _async_send
    await self.connection.send(msg)
  File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 344, in send
    yield from self.write_frame(opcode, data)
  File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 674, in write_frame
    raise ConnectionClosed(self.close_code, self.close_reason)
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
Task exception was never retrieved
future: <Task finished coro=<Connection._async_send() done, defined at /home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/connection.py:61> exception=ConnectionClosed('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)>
Traceback (most recent call last):
  File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 669, in write_frame
    yield from self.writer.drain()
  File "/usr/lib/python3.6/asyncio/streams.py", line 333, in drain
    yield from self._protocol._drain_helper()
  File "/usr/lib/python3.6/asyncio/streams.py", line 204, in _drain_helper
    raise ConnectionResetError('Connection lost')
ConnectionResetError: Connection lost

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/pyppeteer/connection.py", line 64, in _async_send
    await self.connection.send(msg)
  File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 344, in send
    yield from self.write_frame(opcode, data)
  File "/home/d33tah/virtualenv-py3/lib/python3.6/site-packages/websockets/protocol.py", line 674, in write_frame
    raise ConnectionClosed(self.close_code, self.close_reason)
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason

What's wrong? I can see that pyppeteer has an atexit handler defined, why is it misbehaving?

4

0 回答 0