Re: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

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

From: Jean-Paul Calderone <exarkun@divmod.com>
Date: Mon Mar 13 2006 - 04:41:11 CET

On 12 Mar 2006 17:56:37 -0800, Raymond Hettinger <python@rcn.com> 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 needed:
>
> gil.acquire(BLOCK=True)
> try:
> #do some transaction that needs to be atomic
> finally:
> gil.release()
>

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.setcheckinterval(None) seems somewhat natural, though. Perhaps that would be a fruitful direction to explore.

Jean-Paul
Received on Sun Apr 30 11:40:30 2006