labgrid-project / labgrid

Embedded systems control library for development, testing and installation
https://labgrid.readthedocs.io/
Other
327 stars 164 forks source link

DeprecationWarning: There is no current event loop #1056

Open kjeldflarup opened 1 year ago

kjeldflarup commented 1 year ago

I get an annoying warning at the end of my pytest session, when running on the latest master

test_setup/test_setup.py::test_setup_ip
  /usr/local/lib/python3.10/dist-packages/labgrid/remote/client.py:1238: DeprecationWarning: There is no current event loop
    loop = asyncio.get_event_loop()

test_setup/test_setup.py::test_setup_ip
  /usr/local/lib/python3.10/dist-packages/autobahn/asyncio/websocket.py:300: DeprecationWarning: There is no current event loop
    self.loop = loop or asyncio.get_event_loop()

test_setup/test_setup.py::test_setup_ip
  /usr/local/lib/python3.10/dist-packages/autobahn/asyncio/wamp.py:238: DeprecationWarning: There is no current event loop
    loop = asyncio.get_event_loop()

I tried to update autobahn to latest version, but the error stil exists. Anybody knows why this warning comes.

Bastian-Krause commented 1 year ago

What exact Python version are you using?

See the deprecation notices in https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop. Python 3.10.0–3.10.8 emitted these warnings by mistake in some cases.

The event loop has to be created and set explicitly now before asyncio.get_event_loop() is called. So to get rid of all these warnings, we need to make sure that this is the case. I guess that's the job of autobahn in most cases. In the client we probably need to do this ourselves, i.e. here.