this is driving me insane. I'm working with python3 multiprocessing pool of size 3, and I'm creating a log for each process. Only the first 3 logs are created!!! what am I missing?
from time import sleep
import logging, os, multiprocessing as mp
def do_it(proc_num):
log_file = f'{proc_num}.log'
print(f"start {proc_num} {os.getpid()} {log_file}")
logging.basicConfig(filename=log_file, level=logging.INFO)
try:
for iter in range(5):
sleep(1)
logging.info(f"{proc_num}: hello {iter}")
finally:
print(f"finalizing {proc_num}")
logging.shutdown()
logger = logging.getLogger()
logger.handlers[0].flush()
sleep(3)
if __name__ == '__main__':
pool = mp.Pool(3)
pool.map(do_it, [1, 2, 3, 4, 5, 6, 7])
pool.close()
and the result:
ls *.log
1.log 2.log 3.log
wat?!?!
NOTE: NOT the same as How should I log while using multiprocessing in Python? because I WANT a separate logfile per process.