Last active
December 10, 2019 00:01
-
-
Save FanchenBao/d34ca0e9576e24745aed1c500a23dfc2 to your computer and use it in GitHub Desktop.
Expanded demo code for Python3 logging with multiprocessing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
queue = multiprocessing.Queue(-1) | |
# set up main logger following example from work_process | |
worker_configurer(queue) | |
main_logger = logging.getLogger('main') | |
listener = multiprocessing.Process( | |
target=listener_process, args=(queue,)) | |
listener.start() | |
main_logger.info('Logging from main') | |
workers = [] | |
for i in range(3): | |
worker = multiprocessing.Process(target=worker_process, args=(queue,)) | |
workers.append(worker) | |
worker.start() | |
for w in workers: | |
w.join() | |
main_logger.info('main function ends') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment