[issue9136] RuntimeError when profiling Decimal

Stefan Krah report at bugs.python.org
Thu Jul 1 13:10:36 CEST 2010


Stefan Krah <stefan-usenet at bytereef.org> added the comment:

Mark Dickinson <report at bugs.python.org> wrote:
> 
> Mark Dickinson <dickinsm at gmail.com> added the comment:
> 
> class Context(object):
>     def __init__(self):
>         for name, val in locals().items():
>             setattr(self, name, val)
> 
> 
> Isn't this dodgy anyway, since 'name' and 'val' end up going into locals()?  I wonder why the RuntimeError *isn't* raised for a normal 'Context()' call (i.e., not via profile).

Indeed, and it seems to depend on how name and vals are used:

...     print(locals())
... 
{'name': '__builtins__', 'val': <module 'builtins' (built-in)>, '__builtins__': <module 'builtins' (built-in)>, '__package__': None, 'Context': <class '__main__.Context'>, '__name__': '__main__', '__doc__': None}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration

...     pass
... 
>>> locals()
{'name': '__doc__', 'val': None, '__builtins__': <module 'builtins' (built-in)>, '__package__': None, 'Context': <class '__main__.Context'>, '__name__': '__main__', '__doc__': None}
>>>

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9136>
_______________________________________


More information about the Python-bugs-list mailing list