Fix exception when shutting down logging listener

`shutdown_multiprocessing_logging_listener()` shuts down
the logging process which closes the multiprocessing queue
used to shuttle logging data. Before shutting down the
logging process, prevent this process from trying to write
to the logging queue to prevent an exception from occurring when
trying to write to a multiprocessing queue that has been closed
by the other side.

Signed-off-by: Sergey Kizunov <sergey.kizunov@ni.com>
This commit is contained in:
Sergey Kizunov 2018-01-26 03:27:52 -06:00
parent 454ed23f62
commit 3da9b8dd33
No known key found for this signature in database
GPG key ID: 9CEE55A1DE138AAB
2 changed files with 8 additions and 0 deletions

View file

@ -946,6 +946,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':