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

Switch drain_all call to be called from new thread instead of event loop. #16739

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})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bug ticket says the bug is triggered with incremental=True?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my mistake, it is incremental=False as that is what makes configure call _clearExistingHandlers



@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
Loading