Skip to content

Commit 729bea8

Browse files
authored
Merge pull request #401 from djarecka/loop_selector
using asyncio.SelectorEventLoop() to get a loop
2 parents 0c90c93 + 3a8cb10 commit 729bea8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pydra/engine/helpers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,17 @@ def get_open_loop():
648648
"""
649649
if os.name == "nt":
650650
loop = asyncio.ProactorEventLoop() # for subprocess' pipes on Windows
651-
asyncio.set_event_loop(loop)
652651
else:
653-
loop = asyncio.get_event_loop()
654-
if loop.is_closed():
652+
try:
653+
loop = asyncio.get_event_loop()
654+
# in case RuntimeError: There is no current event loop in thread 'MainThread'
655+
except RuntimeError:
655656
loop = asyncio.new_event_loop()
656657
asyncio.set_event_loop(loop)
658+
else:
659+
if loop.is_closed():
660+
loop = asyncio.new_event_loop()
661+
asyncio.set_event_loop(loop)
657662
return loop
658663

659664

0 commit comments

Comments
 (0)