Sometimes I need to use multiprocessing with functions with no arguments. I wish I could do something like:
from multiprocessing import Pool
def f(): # no argument
return 1
# TypeError: f() takes no arguments (1 given)
print Pool(2).map(f, range(10))
I could do Process(target=f, args=())
, but I prefer the syntax of map
/ imap
/ imap_unordered
. Is there a way to do that?
f
to take one argument and ignore it? – Royalroyalistmap
imply that you're mapping a function to a sequence of inputs, so that's what you get. Whether you decide to ignore that argument, or create a wrapper function that's up to you. – Residuary