-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
logging deadlock when dictConfig
or fileConfig
used concurrently with custom handlers
#96727
Comments
I don't think this is a bug in |
I agree this example looks contrived. However we did see it in production. Both of the following possibilities seem reasonable:
These are sufficient to lock the logging module within an That said, I'm not sure what the right solution here is. Some alternatives:
|
I prefer to just add documentation - you need an unusual set of circumstances to hit this (very specialised handler and repeated configuration during program execution), and in this case the very few people who need to do this and hit a deadlock will need to find a workaround. |
…to locking. (pythonGH-96948) (cherry picked from commit 6ad47b4) Co-authored-by: Vinay Sajip <[email protected]>
…espect to locking. (pythonGH-96948) (cherry picked from commit 6ad47b4) Co-authored-by: Vinay Sajip <[email protected]>
Bug report
The attached code below fairly reliably reproduces the deadlock.
There is a module level lock in
logging/__init__.py
. Each handler has its own lock also, implemented as an instance attribute.Calling
dictConfig
(orfileConfig
) locks them in this order:Calling some
logging
functions from within a customemit()
can lock in this order:emit
calls into a library that useslogging.getLogger()
, it will acquire the module lock)The same issue exists with
fileConfig
. Note callingfileConfig
during program execution is ok as per the docs: This function can be called several times from an application, allowing an end user to select from various pre-canned configurations (if the developer provides a mechanism to present the choices and load the chosen configuration).While
emit
may not directly include code tologging.getLogger()
it may call into another library that happens to do that. Evenlogger.isEnabledFor
andlogger.setLevel
etc acquire the module lock and have the same issue.Your environment
Code to reproduce deadlock
Call stacks that deadlocked
The text was updated successfully, but these errors were encountered: