Managing a queue of subprocesses?

cypher543 david at cypherspace.info
Sat Dec 30 12:28:31 EST 2006


That was a very good answer, and it sure sounds like it would work.
However, I failed at implementing it. :( My updated runQueue() function
is:

def runQueue(self):
	self.buildProcess = None
	count = 1 # current position in the queue
	while True:
		if self.buildProcess is None:
			self.execute(self.cmdQueue[count][2], self.cmdQueue[count][0],
self.cmdQueue[count][1])
			count = count + 1
		else:
			# I'm not really sure what to put here

I pretty sure I did all of that wrong. ;) Also, how exactly would I
redirect stderr to another place?

On Dec 30, 12:22 am, Tom Plunket <t... at fancy.org> wrote:
> cypher543 wrote:
> > self.buildPID = subprocess.Popen(buildCmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)Instead of calling it self.buildPID, you might just call it
> self.buildProcess or something.  It's actually a Popen object that gets
> returned.
>
> So yes you can do what you want:
>
> __init__ self.buildProcess to None.  Then, in execute(), if
> (self.buildProcess is None) or (self.buildProcess.poll() is not None)
> start the next process.
>
> You've got to wait for one process to end before starting the next one,
> it's really that easy.  So, don't just go ahead and fire them all
> instantly.  Possibly what you want to do instead is have runQueue() do
> the check somehow that there's no active process running.
>
> What I would do, have runQueue() check to see if self.buildProcess is
> None.  If it is None, fire the next process in the queue.  If it isn't
> None, then check to see if it's ended.  If it has ended, then set
> self.buildProcess to None.  Next UI update the next step in the queue
> gets done.  Mind that you'll have to modify the queue as you go, e.g.
> self.queue = self.queue[1:].
>
> Finally, consider piping stderr separately, and direct its output to a
> different window in your GUI.  You could even make that window pop open
> on demand, if errors occur.
> 
> good luck,
> -tom!
> 
> --




More information about the Python-list mailing list