question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'RuntimeError: Event loop is closed' when running under Windows

See original GitHub issue

When running dinghy under windows I’m getting an ‘Event loop is closed’ error from the asyncio lib, even though the output file is created without issues.

The exact same command runs fine under Ubuntu, without exceptions - same repository, github token, dinghy version; error only happens on windows.

  • Windows version: Windows 10 20H2 19042.1766, 64b
  • Python version: 3.9.1 (64b)
  • Dinghy version: 0.12.0

Note: the digest.html file was generated fine, so the exception thrown might be a minor issue related to resource cleanup.

Error log

C:\Users\heckler>python3 -m dinghy https://github.com/heckler/home-assistant-config
Wrote digest: digest.html
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000221711D58B0>
Traceback (most recent call last):
  File "C:\Users\heckler\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\heckler\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\heckler\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Users\heckler\AppData\Local\Programs\Python\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 0x00000221711D58B0>
Traceback (most recent call last):
  File "C:\Users\heckler\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\heckler\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\heckler\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
    self._check_closed()
  File "C:\Users\heckler\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
graingertcommented, Aug 3, 2022

you only need to ignore the runtime error rather than switching over to the SelectorEventLoop:

import sys


def unraisablehook(unraisable, /, _old_hook=sys.unraisablehook):
    if unraisable.err_msg == "RuntimeError: Event loop is closed" and isinstance(
        unraisable.object, _ProactorBasePipeTransport
    ):
        return
    return _old_hook(unraisable)

sys.unraisablehook = unraisablehook

(more people should use the ProactorEventLoop!)

1reaction
graingertcommented, Aug 3, 2022

@graingert That’s a good comment! 👀

This is dark arts. Is it documented? Might be worth a blog post…

Interesting.

https://vstinner.github.io/sys-unraisablehook-python38.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Asyncio Event Loop is Closed" when getting loop
As of Python 3.7, the process of creating, managing, then closing the loop (as well as a few other resources) is handled for...
Read more >
Python 3.8+ raises "RuntimeError: Event Loop is closed" on ...
aclose finishes, which means the socket is actually deleted upon garbage collection, and by then I suppose the event loop is already closed......
Read more >
RuntimeError: Event loop is closed : r/learnpython
Currently learning about async, and it's been a real challenge converting sync -> async. For example, the script below parses URLs from a...
Read more >
asyncio runtimeerror event loop is closed
To workaround this, you need to run event loop in forever loop and close manually. Following code will cover both windows and other...
Read more >
Event Loop — Python 3.11.1 documentation
Raise a RuntimeError if there is no running event loop. This function can only be called from a coroutine or a callback. New...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found