start () def runs_in_subprocess (): print ( "About to log." ) logging. error ( "hello, I just did something" ) Thread ( target = write_logs ). addHandler ( QueueHandler ( _log_queue )) # Our parent process is running a thread thatĭef write_logs (): while True : logging. _log_queue = Queue () QueueListener ( _log_queue, logging. ![]() # from that queue and writes messages to a file: Import logging from threading import Thread from queue import Queue from logging.handlers import QueueListener, QueueHandler from multiprocessing import Pool def setup_logging (): # Logs get written to a queue, and then a thread reads (Note that none of these examples were tested on Windows I’m focusing on the *nix platform here.) Python provides a handy module that allows you to run tasks in a pool of processes, a great way to improve the parallelism of your program. Let’s begin! Introducing multiprocessing.Pool
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |