I'm not really a Python expert, so excuse me if this is really obvious. I'm trying to run a script using asyncio. Relevant bits of code:
import websockets
import asyncio
stream = websockets.connect(<resource_uri>)
async def main():
async with stream as receiver:
while True:
data = receiver.recv()
# do stuff
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
When I run this, I get:
DeprecationWarning: There is no current event loop loop = asyncio.get_event_loop()
Similarly, using
''' loop = asyncio.get_running_loop() '''
instead, I get
RuntimeError: no running event loop.
Any ideas? I guess it's something to do with main() not running in the correct thread...
I'm using Python 3.10.