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

Jean-Paul Calderone exarkun at divmod.com
Sun Mar 12 22:41:11 EST 2006


On 12 Mar 2006 17:56:37 -0800, Raymond Hettinger <python at 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



More information about the Python-list mailing list