Skip to content

Commit

Permalink
Switch drain_all call to be called from new thread instead of event…
Browse files Browse the repository at this point in the history
… loop. (#16739)
  • Loading branch information
jeanluciano authored Jan 17, 2025
1 parent ea87722 commit c5d1b99
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions flows/setup_logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
This is a regression tests for https://github.com/PrefectHQ/prefect/issues/16115
"""

import logging
from logging.config import dictConfig

from prefect import flow

logger = logging.getLogger(__name__)
logger.setLevel("WARNING")

dictConfig({"version": 1, "incremental": False})


@flow
def myflow():
return "Hello"


if __name__ == "__main__":
result = myflow()

assert result == "Hello"
4 changes: 2 additions & 2 deletions src/prefect/logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def flush(cls) -> None:
)

# Not ideal, but this method is called by the stdlib and cannot return a
# coroutine so we just schedule the drain in the global loop thread and continue
from_sync.call_soon_in_loop_thread(create_call(APILogWorker.drain_all))
# coroutine so we just schedule the drain in a new thread and continue
from_sync.call_soon_in_new_thread(create_call(APILogWorker.drain_all))
return None
else:
# We set a timeout of 5s because we don't want to block forever if the worker
Expand Down

0 comments on commit c5d1b99

Please sign in to comment.