Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Fix <RuntimeError: Event loop is closed> in windows #504

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

Hansimov
Copy link
Contributor

@Hansimov Hansimov commented Jun 6, 2023

Issue Description

When use ayncio.run() in Windows like this:

self.response = asyncio.run(self.send_to_bing(echo, echo_prompt))

It would raise a RuntimeError: Event loop is closed:

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

Solution

import platform
...
if platform.system() == "Windows":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

References

Copy link
Owner

@acheong08 acheong08 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate Windows

@acheong08 acheong08 merged commit 380b01f into acheong08:master Jun 6, 2023
13 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants