Merge pull request #45707 from skizunov/develop2

Fix exception when shutting down logging listener
This commit is contained in:
Nicole Thomas 2018-01-30 08:28:09 -05:00 committed by GitHub
commit 38ed46a61a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -933,6 +933,12 @@ def shutdown_multiprocessing_logging():
logging.root.removeHandler(__MP_LOGGING_QUEUE_HANDLER)
__MP_LOGGING_QUEUE_HANDLER = None
__MP_LOGGING_CONFIGURED = False
if not logging.root.handlers:
# Ensure we have at least one logging root handler so
# something can handle logging messages. This case should
# only occur on Windows since on Windows we log to console
# and file through the Multiprocessing Logging Listener.
setup_console_logger()
finally:
logging._releaseLock()
@ -946,6 +952,12 @@ def shutdown_multiprocessing_logging_listener(daemonizing=False):
# We're in the MainProcess and we're not daemonizing, return!
# No multiprocessing logging listener shutdown shall happen
return
if not daemonizing:
# Need to remove the queue handler so that it doesn't try to send
# data over a queue that was shut down on the listener end.
shutdown_multiprocessing_logging()
if __MP_LOGGING_QUEUE_PROCESS is None:
return
if __MP_LOGGING_QUEUE_PROCESS.is_alive():

View file

@ -261,6 +261,8 @@ class OptionParser(optparse.OptionParser, object):
)
)
if self._setup_mp_logging_listener_ is True:
# Stop logging through the queue
log.shutdown_multiprocessing_logging()
# Stop the logging queue listener process
log.shutdown_multiprocessing_logging_listener(daemonizing=True)
if isinstance(msg, six.string_types) and msg and msg[-1] != '\n':