<#3407 Fix run_sync failure when called from a run...
# flyte-github
a
#3407 Fix run_sync failure when called from a running event loop Pull request opened by pingsutw Summary • Fix
RuntimeError: Cannot run the event loop while another loop is running
when
FlyteRemote.execute()
is called from within an already-running async event loop (e.g., Flask with Gunicorn) •
_AsyncLoopManager.run_sync()
now detects a running loop and spawns a short-lived thread with its own event loop via
asyncio.run()
, preserving context variables with
contextvars.copy_context()
• The original
_TaskRunner
path remains unchanged for non-async contexts Test plan • Added
test_run_sync_from_running_event_loop
— verifies
run_sync
works when called from within a running event loop • Added
test_run_sync_from_running_event_loop_with_exception
— verifies exceptions propagate correctly in this path • All existing tests in
tests/flytekit/unit/utils/test_asyn.py
pass (8/8) flyteorg/flytekit