Last active
January 4, 2019 10:55
-
-
Save YieldNull/6762de0bbf23b245681102e9369f17e3 to your computer and use it in GitHub Desktop.
multithread_logging.py
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
import sys | |
import logging | |
from multiprocessing.pool import Pool | |
logging.basicConfig(stream=sys.stdout, level=logging.INFO, | |
format='%(asctime)s - %(processName)s %(threadName)s - %(name)s - %(levelname)s - %(message)s') | |
if __name__ == "__main__": | |
def job(name): | |
logger = logging.getLogger(name) | |
logger.info("balabala") | |
size = 5 | |
pool = Pool(size) | |
futures = [pool.apply_async(job, args=('Job-%d' % i, )) for i in range(size)] | |
[f.get() for f in futures] | |
pool.close() | |
pool.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment