In python 3, you can now open a file safely using the with clause like this:
with open("stuff.txt") as f:
data = f.read()
Using this method, I don't need to worry about closing the connection
I was wondering if I could do the same for the multiprocessing. For example, my current code looks like:
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
pool.starmap(function,list)
pool.close()
pool.join()
Is there any way I could use a with clause to simplify this?

所有评论(0)