Skip to content

Instantly share code, notes, and snippets.

@korakot
Last active January 3, 2024 02:15
Show Gist options
  • Save korakot/f1d835321fa14075227add61b90debb3 to your computer and use it in GitHub Desktop.
Save korakot/f1d835321fa14075227add61b90debb3 to your computer and use it in GitHub Desktop.
Use asyncio (async) in Colab
import nest_asyncio
nest_asyncio.apply()
@thanakijwanavit
Copy link

could you please share how it works

thanks ;)

@korakot
Copy link
Author

korakot commented Dec 8, 2020

I forgot how exactly. But if you import asyncio and there's a problem in Colab, you can try the code above.

@thanakijwanavit
Copy link

ok, i had that problem just now lol

@korakot
Copy link
Author

korakot commented Aug 10, 2022

This comment from mohamed mofid is missing?

I think you just make a new event loop and pass it to nest_asyncio.apply() the start using it like this:

    self.loop = asyncio.new_event_loop()
    nest_asyncio.apply(self.loop)
    asyncio.set_event_loop(self.loop)

I found that in GitHub:
https://github.com/erdewit/nest_asyncio/blob/master/tests/nest_test.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment