Skip to content

Instantly share code, notes, and snippets.

@YieldNull
Last active January 4, 2019 10:55
Show Gist options
  • Save YieldNull/6762de0bbf23b245681102e9369f17e3 to your computer and use it in GitHub Desktop.
Save YieldNull/6762de0bbf23b245681102e9369f17e3 to your computer and use it in GitHub Desktop.
multithread_logging.py
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