I am using multiprocessing.Pool to run a number of independent tasks in parallel. Not so much different from the basic example in the python docs:
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
with Pool(5) as p:
print(p.map(f, [1, 2, 3]))
I would like each item to log to a separate file. I log various info from other modules in my codebase and some third-party packages (none of them is multiprocessing aware). So, for example, I would like this:
import logging
from multiprocessing import Pool
def logOnDisk(x):
logging.info("hello world")
if __name__ == '__main__':
with Pool() as p:
p.map(logOnDisk, ["ping", "pong", "foo", "bar"])
to write on disk:
ping.log
pong.log
foo.log
bar.log
Each file should contain the string "hello world". How do I achieve this?