Skip to content

Commit

Permalink
Fix autodetect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Blanca-Fuentes committed Dec 16, 2024
1 parent 010b8fb commit 00b25b8
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions reframe/frontend/executors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
StatisticsError,
TaskExit)
from reframe.core.schedulers.local import LocalJobScheduler
from reframe.frontend.executors import all_tasks
from reframe.frontend.printer import PrettyPrinter

ABORT_REASONS = (AssertionError, FailureLimitError,
Expand Down Expand Up @@ -813,16 +814,33 @@ def execute(self, testcases):


def asyncio_run(coro):
loop = asyncio.get_event_loop()

if loop.is_running():
try:
loop = asyncio.get_event_loop()
for task in all_tasks(loop):
if isinstance(task, asyncio.tasks.Task):
try:
task.cancel()
except RuntimeError:
pass
if loop.is_closed():
loop = asyncio.new_event_loop()
watcher = asyncio.get_child_watcher()
if isinstance(watcher, asyncio.SafeChildWatcher):
# Detach the watcher from the current loop to avoid issues
watcher.close()
watcher.attach_loop(None)
asyncio.set_event_loop(loop)
if isinstance(watcher, asyncio.SafeChildWatcher):
# Reattach the watcher to the new loop
watcher.attach_loop(loop)
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

try:
loop.run_until_complete(coro)
except (Exception, KeyboardInterrupt):
for task in all_tasks(loop):
if isinstance(task, asyncio.tasks.Task):
task.cancel()
loop.close()
return
else:
try:
loop.run_until_complete(coro)
loop.close()
return
finally:
loop.close()

0 comments on commit 00b25b8

Please sign in to comment.