Skip to content

Instantly share code, notes, and snippets.

@sin-tanaka
Last active September 10, 2018 14:38
Show Gist options
  • Save sin-tanaka/923572dbb692c86633d249f729e35388 to your computer and use it in GitHub Desktop.
Save sin-tanaka/923572dbb692c86633d249f729e35388 to your computer and use it in GitHub Desktop.
tornado >= 5以上がインストールされたjupyter-notebook上でevent_loopを扱うとRuntimeError: This event loop is already runningになる ref: https://qiita.com/sin_tanaka/items/56eb1b8a677fb9b50f7b
import asyncio
from pyppeteer import launch
loop = asyncio.get_event_loop()
async def main():
browser = await launch()
page = await browser.newPage()
await page.goto('http://example.com')
await page.screenshot({'path': 'example.png'})
await browser.close()
loop.run_until_complete(main())
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-16-b0a5d64b1fb0> in <module>()
----> 1 loop.run_until_complete(main())
~/.anyenv/envs/pyenv/versions/3.6.4/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future)
452 future.add_done_callback(_run_until_complete_cb)
453 try:
--> 454 self.run_forever()
455 except:
456 if new_task and future.done() and not future.cancelled():
~/.anyenv/envs/pyenv/versions/3.6.4/lib/python3.6/asyncio/base_events.py in run_forever(self)
406 self._check_closed()
407 if self.is_running():
--> 408 raise RuntimeError('This event loop is already running')
409 if events._get_running_loop() is not None:
410 raise RuntimeError(
RuntimeError: This event loop is already running
$ pip install tornado<=4.5.3
$ pip install jupyter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment