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

RuntimeError: Event loop is closed #31

Closed
CausticD opened this issue Apr 9, 2021 · 9 comments
Closed

RuntimeError: Event loop is closed #31

CausticD opened this issue Apr 9, 2021 · 9 comments

Comments

@CausticD
Copy link

CausticD commented Apr 9, 2021

Hi,

Using a very simple test code on Python 3.9:

device_manager = TPLinkDeviceManager(username, password)
device_name = "Test"
device = device_manager.find_device(device_name)
if device:
  print(f'Found {device.model_type.name} device: {device.get_alias()}')
  device.toggle()

I get the following output:

Found HS100 device: Test
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001846A0AA310>
Traceback (most recent call last):
  File "C:\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Python39\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Python39\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001846A0AA310>
Traceback (most recent call last):
  File "C:\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Python39\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Python39\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

The plug toggles fine, but the runtime error is always thrown.

@piekstra
Copy link
Owner

piekstra commented Apr 9, 2021

@CausticD thank you for bringing this to my attention and for the detailed content! I will be taking a look at this today and prioritizing it over feature development as it looks like a bug to me.

@piekstra
Copy link
Owner

piekstra commented Apr 9, 2021

@CausticD I had an HS100 on hand and unfortunately was not able to reproduce this. I was using a fresh install of Python 3.9.4 on Mac OS X. What version of Python 3.9 are you using and on what OS?

@piekstra
Copy link
Owner

piekstra commented Apr 9, 2021

Doing some digging, it looks like this is most likely a Windows-specific Python issue aio-libs/aiohttp#4324

I will see if it makes sense to add in a workaround to this library to silence the exception being thrown as it looks concerning but is actually harmless to the library's functionality.

@piekstra
Copy link
Owner

piekstra commented Apr 9, 2021

@CausticD when you have a moment, and assuming you were running on Windows, could you try running this Python script as a workaround to the issue? https://gist.github.com/piekstra/3b579d8843232d897eca657c1577f5a7

I am not sure if it simply has to be run once on a Windows machine and will then resolve the issue thereafter. Given it is a workaround and the libraries haven't fixed the issue yet in a public release, I would not want to add this to be a default part of this library.

If it successfully silences the exception for you, I will simply mention it in the README.md for this library.

@CausticD
Copy link
Author

CausticD commented Apr 9, 2021

@piekstra Wow, that was fast! Many thanks. Yup, a brand new 3.9.4 install on Windows and yes that does fix it! However, it seems to be needed every time in my very limited testing.

@piekstra
Copy link
Owner

piekstra commented Apr 9, 2021

@CausticD that's actually good news that it requires it every time! That alleviates a concern I had about building it into the library and potentially causing some sort of permanent change to behaviors on someone's system. I will have a pull request / branch up shortly that I'd like you to test out when you get a chance.

@piekstra
Copy link
Owner

piekstra commented Apr 9, 2021

Alright @CausticD try this out: #32

In theory you should be able to run the same code snippet as in your original post and you won't see the exception.

@CausticD
Copy link
Author

CausticD commented Apr 9, 2021

@piekstra Yup, that seems good to me. Reverted my change, added yours and still fine.

@piekstra
Copy link
Owner

piekstra commented Apr 9, 2021

@CausticD excellent! I will add it in officially then and cut a release with the fix.

@piekstra piekstra closed this as completed Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants