Is there an equivalence of "await" in Google Colab?

3k Views Asked by At

I was trying to solve the problem related to pyshark on runtime error "This event loop is already running". However, when I was following the advise online to add the following code.

await CapFile.packets_from_tshark(print_pkt)

I wasn't able to do it because there wasn't an equivalence of await in Google Colab? What should I do to circumvent the problem? Any answer will be appreciated!

1

There are 1 best solutions below

1
On BEST ANSWER

This is the hack I use on my Colabs:

import nest_asyncio
nest_asyncio.apply()

import asyncio
awaitfn = lambda x: asyncio.get_event_loop().run_until_complete(x)

And then:

awaitfn(CapFile.packets_from_tshark(print_pkt))

Edit (Feb 2022): The underlying issue is that Google Colab uses IPython 5.5 from 2017. You can manually upgrade it by running:

!pip install ipython ipykernel --upgrade

The Colab dev team seams to be working on this.