Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top level await #1553

Closed
FredrikNoren opened this issue Sep 4, 2020 · 5 comments
Closed

Top level await #1553

FredrikNoren opened this issue Sep 4, 2020 · 5 comments
Labels

Comments

@FredrikNoren
Copy link

  • Describe the current behavior:
    I'm having some trouble running pyppeteer in colab (which I'm using to communicate with a reinforcement learning environment called Derk's Gym). It's using async/away, and from what I understand the "normal" way to make that work is to use nest_asyncio. But pyppeteer unfortunately has a bug which prevents it being used with nest_asyncio.
    From what I gather ipython/jupyter supports top level awaits, which would solve this problem. Is that something colab has on the roadmap? Or are there other solutions to running async code in colab that I'm not aware of?

  • Describe the expected behavior:
    Would be great if pyppeteer worked :)

  • Link (not screenshot!) to a minimal, public, self-contained notebook that
    reproduces this issue (click the Share button, then Get Shareable Link):

!pip install pyppeteer

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch()
    page = await browser.newPage()
    await page.goto('https://example.com')
    await page.screenshot({'path': 'example.png'})
    await browser.close()

asyncio.get_event_loop().run_until_complete(main())
@blois
Copy link
Contributor

blois commented Sep 4, 2020

We need to get an ipython upgrade to allow pyppeteer working, this will take a bit of time. In the meantime I've been downgrading tornado to allow the asyncio to work.

from google.colab import output
with output.temporary():
  !pip install pyppeteer tornado==4.5.3 
  !apt update
  !apt install chromium-chromedriver

import os
import signal

# Kill the process to restart with the older tornado version.
os.kill(os.getpid(), signal.SIGTERM)

@FredrikNoren
Copy link
Author

@blois Thanks! That worked

@iann838
Copy link

iann838 commented Nov 30, 2021

For those who need TOP LEVEL AWAIT LITERALLY. Upgrade your ipython and ipykernel, because it's of the old version that does not support this feature.

!pip install ipython ipykernel --upgrade

After this restart runtime and you're good to go.

@craigcitro
Copy link
Contributor

Internal tracking: b/207773817

@metrizable
Copy link
Contributor

The Colab runtime has been upgraded to ipython==7.34 and, although YMMV, asyncio machinery appears to be working:

4uwubyeRdAvbtwK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants