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

Fix osrf.py_common.process_utils.get_loop() implementation #70

Merged
merged 2 commits into from
Jan 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions osrf_pycommon/process_utils/get_loop_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ def get_loop_impl(asyncio):
return asyncio.get_event_loop()
# Setup this thread's loop and return it
if os.name == 'nt':
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
try:
loop = asyncio.get_event_loop()
if not isinstance(loop, asyncio.ProactorEventLoop):
# Before replacing the existing loop, explicitly
# close it to prevent an implicit close during
# garbage collection, which may or may not be a
# problem depending on the loop implementation.
loop.close()
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
except (RuntimeError, AssertionError):
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
else:
try:
loop = asyncio.get_event_loop()
Expand Down