[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Ideas for creating processes

J

3/10/2010 10:05:00 PM

On Wed, Mar 10, 2010 at 16:52, J <dreadpiratejeff@gmail.com> wrote:
> the quick and dirty would be (as I'm imagining it at the moment):
> for path in pathlist:
>    chdir into path
>    execute rsync or zsync
>
> but that gets me moving into one dir, updating, then moving into another.
>
> What I was wondering about though, is spawning off separate rsync
> processes to run concurrently (each rsync will hit a different remote
> dir for each local dir)
>
> so I'm trying to figure out a good way to do this:
>
> for path in pathlist:
>    kick off an individual rsync|zsync process to update path

And now I'm looking at subprocess and I can set shell=True and it will
intrepret special characters like &

So could I do something like this:

for item in pathlist:
subprocess.Popen('rsync command &', shell=True)

and simply wait unti they are all done?
1 Answer

Piet van Oostrum

3/13/2010 3:41:00 PM

0

>>>>> J <dreadpiratejeff@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@vanoostrum.org>
WWW: http://pietvanoo...
PGP key: [8DAE142BE17999C4]
Nu Fair Trade woonaccessoires op http://www...