Re: Managing a queue of subprocesses?



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...@xxxxxxxxx> 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!

--

.



Relevant Pages

  • Re: [patch] Real-Time Preemption, deactivate() scheduling issue
    ... > back on the runqueue after 10 ms. ... TASK_RUNNING state in run queue. ... > rescheduling is volentery or forced (a preemption). ... > task itself has called schedule() or schedule_timeoutit has to go out ...
    (Linux-Kernel)
  • [PATCH -v2 6/7] wake up balance RT
    ... This patch adds pushing of overloaded RT tasks from a runqueue that is ... having tasks added to the run queue. ... TODO: We don't cover the case of waking of new RT tasks. ...
    (Linux-Kernel)
  • Re: Managing a queue of subprocesses?
    ... It's actually a Popen object that gets ... have runQueue() check to see if self.buildProcess is ... fire the next process in the queue. ...
    (comp.lang.python)
  • [patch 7/8] wake up balance RT
    ... This patch adds pushing of overloaded RT tasks from a runqueue that is ... having tasks added to the run queue. ... TODO: We don't cover the case of waking of new RT tasks. ...
    (Linux-Kernel)