I am reading this
http://docs.python.org/dev/library/multiprocessing.html
In particular this
p = multiprocessing.Process(target=time.sleep, args=(1000,))
I tried the same thing, but if I remove the “,” after 1000 it doesn’t work. So my question is what is the semantic behind the args=(1000,) in this case? What is the difference if I put a comma and not ?
p/s: I believe it’s a fundamental issue, if it is can someone point me to some further reading if possible? thanks.
Thanks.
Regards,
Andy.
If you just put
(1000), Python assumes you’re just evaluating the expression as math, hence it gets simplified to just 1000. Think of the result of5 + (1000) + 4.Just as the expression above would get simplified to
1009, here is what your line looks like once things have been simplified:You can see that this is not the same thing at all.
argsis supposed to be a tuple of arguments, not a single integer.If you put
(1000,), Python can tell you are looking for a tuple which only contains one element, since that expression is differentiable from a simple arithmetic expression, so you end up passing in the correct thing.