Am I not seeing the Error?
Zachary Ware
zachary.ware+pylist at gmail.com
Mon Aug 12 11:37:21 EDT 2013
On Mon, Aug 12, 2013 at 9:04 AM, Devyn Collier Johnson
<devyncjohnson at gmail.com> wrote:
>
> Zachary, are you, Ned, and Terry trying to say the syntax should be
>
> job = multiprocessing.Process(func1(), func2())
>
> not
>
> job = multiprocessing.Process(func1(); func2())
>
Basically, yes. The first option there is equivalent to this:
func_returns = (func1(), func2())
job = multiprocessing.Process(*func_returns)
The second option is equivalent to this:
job = multiprocessing.Process(func1()
func2())
...which is actually several different syntax errors, depending on how
you look at it. Semi-colon is only ever used in Python as a
substitute for \n-plus-some-spaces. And, since in your original
example, your semi-colons are inside parenthesis, they really have no
effect at all due to implicit line continuation within parens. So
your original line:
JOB_WRITEURGFILES =
multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID);
write2file(SENTEMPPATH, ''); write2file(INPUTMEM, ''));
JOB_WRITEURGFILES.start()
is really:
JOB_WRITEURGFILES =
multiprocessing.Process(write2file('./mem/ENGINE_PID', ENGINEPID)
write2file(SENTEMPPATH, '') write2file(INPUTMEM, ''))
JOB_WRITEURGFILES.start()
It should be obvious now that the syntax error comes from not
separating the arguments to Process.
Trying to read between the lines a little here, I don't think you have
quite figured out how multiprocessing.Process works; that first option
above will only work if func1 returns None and func2 returns a
callable object and the second has no hope. I think this is more
along the lines of what you're really after:
def process_func():
func1()
func2()
if __name__ == '__main__':
job = multiprocessing.Process(target=process_func) # note: no
() after process_func!
job.start()
I'd suggest giving the multiprocessing.Process docs [0] a good
read-through. Keep in mind that Process is just a type like any other
(str, int, list, etc.), and calling its constructor is subject to the
same rules as any other function call.
--
Zach
[0] http://docs.python.org/3/library/multiprocessing#the-process-class
More information about the Python-list
mailing list