Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-13 Thread Raymond Hettinger
[robert] > In very rare cases a program crashes (hard to reproduce) : > > * several threads work on an object tree with dict's etc. in it. Items > are added, deleted, iteration over .keys() ... ). The threads are "good" > in such terms, that this core data structure is changed only by atomic > oper

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-13 Thread anamax
> robert wrote: > Meanwhile I think this is a bug of cPickle.dump: It should use .keys() > instead of free iteration internally, when pickling elementary dicts. > I'd file a bug if no objection. What should happen if there's a delete between the time the .keys() runs and the time that the deleted

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-12 Thread fumanchu
You can also *almost* do it with a tracehook that blocks until released by another thread. See http://projects.amor.org/misc/wiki/PyConquer for the tool I'm sporadically working on that does that (in an effort to test all possible execution paths). The only limitation is that trace functions aren't

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-12 Thread Alex Martelli
Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: ... > This is vaguely possible using sys.setcheckinterval() now, although one > has to pick a ridiculously large number and hope that the atomic operation > takes fewer than that many opcodes. > > Spelling "do not switch threads" as sys.setcheckint

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-12 Thread Jean-Paul Calderone
On 12 Mar 2006 17:56:37 -0800, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > >Thinking about future directions for Python threading, I wonder if >there is a way to expose the GIL (or simply impose a temporary >moratorium on thread switches) so that it becomes easy to introduce >atomicity when need

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-12 Thread Raymond Hettinger
[robert] > In very rare cases a program crashes (hard to reproduce) : > > * several threads work on an object tree with dict's etc. in it. Items > are added, deleted, iteration over .keys() ... ). The threads are "good" > in such terms, that this core data structure is changed only by atomic > oper

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread EleSSaR^
robert si è profuso/a a scrivere su comp.lang.python tutte queste elucubrazioni: > Yes, a "backup" / autosave while all threads are running. It doesn't > matter if 'before' of 'after' another item has been added/deleted > atomically. But it does matter if the autosave happens *while* an item i

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread robert
Tim Peters wrote: > [robert] > >>... >>PS: how does ZODB work with this kind of problem? I thought is uses cPickle? > > > It does. Each thread in a ZODB application typically uses its own > connection to a database. As a result, each thread gets its own > consistent view of database objects,

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread robert
EleSSaR^ wrote: > robert si è profuso/a a scrivere su comp.lang.python tutte queste > elucubrazioni: > > >>own deepcopy: thus, do you already know if the existing deepcopy has the >>same problem as cPickle.dump ?(as the problem araises rarely, it is >>difficult for me to test it out) > >

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread Tim Peters
[robert] > ... > PS: how does ZODB work with this kind of problem? I thought is uses cPickle? It does. Each thread in a ZODB application typically uses its own connection to a database. As a result, each thread gets its own consistent view of database objects, which can (and routinely does) vary

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread EleSSaR^
robert si è profuso/a a scrivere su comp.lang.python tutte queste elucubrazioni: [cut] P.S. I'm very bad at threaded programming. Please verify any of my suggestions ^_^ -- EleSSaR^ <[EMAIL PROTECTED]> -- Togli .xyz dalla mia email per contattarmi. -- http://mail.python.org/mailman/listinfo/

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread EleSSaR^
robert si è profuso/a a scrivere su comp.lang.python tutte queste elucubrazioni: > own deepcopy: thus, do you already know if the existing deepcopy has the > same problem as cPickle.dump ?(as the problem araises rarely, it is > difficult for me to test it out) I don't know the exact specs

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread Alex Martelli
robert <[EMAIL PROTECTED]> wrote: ... > 99.99% no. I would have to use a lock everywhere, where I add or remove > something into a dict or list of the struct. Thats not the purpose of > big thread locks. Such simple operations are already atomic by the > definition of Python - and thanks to the

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread robert
EleSSaR^ wrote: > robert si è profuso/a a scrivere su comp.lang.python tutte queste > elucubrazioni: > > [cut] > > I don't know what's your code like, but a similar error occurred in some of > my software and it was my fault indeed. I think you should either use a > lock, or implement a deepcop

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread robert
Felipe Almeida Lessa wrote: > Em Sáb, 2006-03-11 às 12:49 +0100, robert escreveu: > >>Meanwhile I think this is a bug of cPickle.dump: It should use .keys() >>instead of free iteration internally, when pickling elementary dicts. >>I'd file a bug if no objection. > > > AFAICS, it's a problem w

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread EleSSaR^
robert si è profuso/a a scrivere su comp.lang.python tutte queste elucubrazioni: [cut] I don't know what's your code like, but a similar error occurred in some of my software and it was my fault indeed. I think you should either use a lock, or implement a deepcopy method of your own. -- EleSSa

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread Felipe Almeida Lessa
Em Sáb, 2006-03-11 às 12:49 +0100, robert escreveu: > Meanwhile I think this is a bug of cPickle.dump: It should use .keys() > instead of free iteration internally, when pickling elementary dicts. > I'd file a bug if no objection. AFAICS, it's a problem with your code. You should lock your objec

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread robert
robert wrote: > >> Is a copy.deepcopy ( -> "cPickle.dump(copy.deepcopy(obj),f)" ) an >> atomic opertion with a guarantee to not fail? >> >> Or can I only retry several times in case of RuntimeError? (which >> would apears to me as odd gambling; retry how often?) > > > For an intermediate so

Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread robert
> Is a copy.deepcopy ( -> "cPickle.dump(copy.deepcopy(obj),f)" ) an > atomic opertion with a guarantee to not fail? > > Or can I only retry several times in case of RuntimeError? (which would > apears to me as odd gambling; retry how often?) For an intermediate solution, I'm playing roulette

"RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?

2006-03-11 Thread robert
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are "good" in such terms, that this core data structure is changed only by atomic operations, so that t