Ideas for creating processes
Piet van Oostrum
piet at vanoostrum.org
Sat Mar 13 10:41:12 EST 2010
>>>>> J <dreadpiratejeff at gmail.com> (J) wrote:
>J> And now I'm looking at subprocess and I can set shell=True and it will
>J> intrepret special characters like &
>J> So could I do something like this:
>J> for item in pathlist:
>J> subprocess.Popen('rsync command &', shell=True)
>J> and simply wait unti they are all done?
Using shell=True is often the wrong thing to do. And certainly just to
get a process to run in the background. subprocess will run them in the
background by default. Besides if you do it in the way you propose you
can't wait for them. You can only wait for the shell that starts the
rsync, but that will be finished almost immediately.
>>> import subprocess
>>> p = subprocess.Popen('sleep 1000 &', shell=True)
>>> p.wait()
0
>>>
The wait() returns immediately.
--
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
Nu Fair Trade woonaccessoires op http://www.zylja.com
More information about the Python-list
mailing list