Re: can't delete from a dictionary in a loop

2008-05-17 Thread Scott David Daniels
Eduardo O. Padoan wrote: On Fri, May 16, 2008 at 6:40 PM, Gary Herron <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] wrote: On 16 mai, 23:28, Hans Nowak <[EMAIL PROTECTED]> wrote: Dan Upton wrote: <> ...to solve the immediate problem: for pid in procs_dict.keys(): And then, in Python3, k

Re: can't delete from a dictionary in a loop

2008-05-17 Thread castironpi
On May 17, 3:06 am, George Sakkis <[EMAIL PROTECTED]> wrote: > On May 16, 5:22 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote: > > > > > > > This might be more information than necessary, but it's the best way I > > can think of to describe the question without being too vague. > > > The task: > > > I h

Re: can't delete from a dictionary in a loop

2008-05-17 Thread George Sakkis
On May 16, 5:22 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote: > This might be more information than necessary, but it's the best way I > can think of to describe the question without being too vague. > > The task: > > I have a list of processes (well, strings to execute said processes) > and I want to

Re: can't delete from a dictionary in a loop

2008-05-16 Thread MRAB
On May 16, 10:22 pm, "Dan Upton" <[EMAIL PROTECTED]> wrote: > This might be more information than necessary, but it's the best way I > can think of to describe the question without being too vague. > > The task: > > I have a list of processes (well, strings to execute said processes) > and I want t

Re: can't delete from a dictionary in a loop

2008-05-16 Thread Terry Reedy
"Dan Upton" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | RuntimeError: dictionary changed size during iteration If you do not actually need a dict, an explicitly managed list is an [untested]alternative. maxproc = # procs = [] while True: if len(procs) < maxproc: [populate p

Re: can't delete from a dictionary in a loop

2008-05-16 Thread Eduardo O. Padoan
On Fri, May 16, 2008 at 6:40 PM, Gary Herron <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: >> >> On 16 mai, 23:28, Hans Nowak <[EMAIL PROTECTED]> wrote: >> >>> >>> Dan Upton wrote: >>> for pid in procs_dict: if procs_dict[pid].poll() != None # do the counter updates >

Re: can't delete from a dictionary in a loop

2008-05-16 Thread castironpi
On May 16, 4:51 pm, Hans Nowak <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > On 16 mai, 23:34, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > >> On 16 mai, 23:28, Hans Nowak <[EMAIL PROTECTED]> wrote: > > >>> Dan Upton wrote: > for pid in procs_dict: > > (snip) > >>>    for p

Re: can't delete from a dictionary in a loop

2008-05-16 Thread Hans Nowak
[EMAIL PROTECTED] wrote: On 16 mai, 23:34, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: On 16 mai, 23:28, Hans Nowak <[EMAIL PROTECTED]> wrote: Dan Upton wrote: for pid in procs_dict: (snip) for pid in procs_dict.keys(): I'm afraid this will do the same exact thing. A for loop on a d

Re: can't delete from a dictionary in a loop

2008-05-16 Thread Gary Herron
[EMAIL PROTECTED] wrote: On 16 mai, 23:28, Hans Nowak <[EMAIL PROTECTED]> wrote: Dan Upton wrote: for pid in procs_dict: if procs_dict[pid].poll() != None # do the counter updates del procs_dict[pid] The problem: RuntimeError: dictionary changed size during iterati

Re: can't delete from a dictionary in a loop

2008-05-16 Thread [EMAIL PROTECTED]
On 16 mai, 23:34, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On 16 mai, 23:28, Hans Nowak <[EMAIL PROTECTED]> wrote: > > > > Dan Upton wrote: > > > for pid in procs_dict: (snip) > >for pid in procs_dict.keys(): > > I'm afraid this will do the same exact thing. A for loop on a dict > itera

Re: can't delete from a dictionary in a loop

2008-05-16 Thread Gary Herron
Dan Upton wrote: This might be more information than necessary, but it's the best way I can think of to describe the question without being too vague. The task: I have a list of processes (well, strings to execute said processes) and I want to, roughly, keep some number N running at a time. If

Re: can't delete from a dictionary in a loop

2008-05-16 Thread [EMAIL PROTECTED]
On 16 mai, 23:28, Hans Nowak <[EMAIL PROTECTED]> wrote: > Dan Upton wrote: > > for pid in procs_dict: > > if procs_dict[pid].poll() != None > ># do the counter updates > >del procs_dict[pid] > > > The problem: > > > RuntimeError: dictionary changed size during iteration > > I don't know i

Re: can't delete from a dictionary in a loop

2008-05-16 Thread Hans Nowak
Dan Upton wrote: for pid in procs_dict: if procs_dict[pid].poll() != None # do the counter updates del procs_dict[pid] The problem: RuntimeError: dictionary changed size during iteration I don't know if the setup with the pids in a dictionary is the best way to manage a pool of proc

can't delete from a dictionary in a loop

2008-05-16 Thread Dan Upton
This might be more information than necessary, but it's the best way I can think of to describe the question without being too vague. The task: I have a list of processes (well, strings to execute said processes) and I want to, roughly, keep some number N running at a time. If one terminates, I