logging shutdown (was: Re: [Python-checkins] r61431 - python/trunk/Doc/library/logging.rst)

I think (repeatedly) testing an app through IDLE is a reasonable use case. Would it be reasonable for shutdown to remove logging from sys.modules, so that a rerun has some chance of succeeding via its own import? -jJ On 3/16/08, vinay.sajip <python-checkins@python.org> wrote:
Author: vinay.sajip Date: Sun Mar 16 22:35:58 2008 New Revision: 61431
Modified: python/trunk/Doc/library/logging.rst Log: Clarified documentation on use of shutdown().
Modified: python/trunk/Doc/library/logging.rst ============================================================================== --- python/trunk/Doc/library/logging.rst (original) +++ python/trunk/Doc/library/logging.rst Sun Mar 16 22:35:58 2008 @@ -732,7 +732,8 @@ .. function:: shutdown()
Informs the logging system to perform an orderly shutdown by flushing and - closing all handlers. + closing all handlers. This should be called at application exit and no + further use of the logging system should be made after this call.
.. function:: setLoggerClass(klass) _______________________________________________ Python-checkins mailing list Python-checkins@python.org http://mail.python.org/mailman/listinfo/python-checkins

I think (repeatedly) testing an app through IDLE is a reasonable use case.
I don't disagree, but cleanup of logging may not be all that trivial in some scenarios: for example, if multiple threads have references to handlers, then after shutdown() was called, logging by those threads would fail due to I/O errors - a reasonable outcome. However, logging cannot know if threads contain references to loggers or handlers, and so I do not e.g. remove loggers on shutdown().
Would it be reasonable for shutdown to remove logging from sys.modules, so that a rerun has some chance of succeeding via its own import?
I'm not sure that would be enough in the scenario I mentioned above - would removing a module from sys.modules be a guarantee of removing it from memory? If so, what if still-running threads contained references to loggers etc. - wouldn't they potentially segfault? It's safer, in my view, for the developer of an application to do cleanup of their app if they want to test repeatedly in IDLE. After all, this could involve cleanup of other resources which are nothing to do with logging; and a developer can certainly remove handlers from loggers using the existing API, after ensuring all their threads are done and there are no unaccounted-for references to loggers and handlers. Regards, Vinay Sajip

On 3/19/08, Vinay Sajip <vinay_sajip@red-dove.com> wrote:
I think (repeatedly) testing an app through IDLE is a reasonable use case.
[other threads may still have references to loggers or handlers]
Would it be reasonable for shutdown to remove logging from sys.modules, so that a rerun has some chance of succeeding via its own import?
I'm not sure that would be enough in the scenario I mentioned above - would removing a module from sys.modules be a guarantee of removing it from memory?
No. It will explicitly not be removed from memory while anything holds a live reference. Removing it from sys.modules just means that the next time a module does "import logging", the logging initialization code will run again. It is true that this could cause contention if the old version is still holding an exclusive lock on some output file.
It's safer, in my view, for the developer of an application to do cleanup of their app if they want to test repeatedly in IDLE.
Depending on the issue just fixed, the app may not have a clean shutdown. -jJ
participants (2)
-
Jim Jewett
-
Vinay Sajip