Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Bug report
The documentation forMemoryHandler claims:If flushOnClose is specified as False, then the buffer is not flushed when the handler is closed.
However, as this minimal test shows, it's not always respected. Running this snippet does print "this should not print to the console" to the console.
importlogging,logging.handlerslogging.root.addHandler(logging.handlers.MemoryHandler(capacity=10,flushLevel=logging.ERROR,target=logging.StreamHandler(),flushOnClose=False))logging.warning('this should not print to the console')
It looks like it's theshutdown handler inLib/logging/__init__.py that's doing the flushing.
If you explicitly close the handler before the process exits, you get the expected behavior...the log message isn't printed to the console. Which is why theunit test passes, that's what it's testing.
Your environment
I initially noticed this in python 3.8.13 on MacOS 12.5 (21G72). I can repro in the other python versions I have installed on that same macbook, 3.9.2 and 3.10.4.