![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.python archiveRe: "RuntimeError: dictionary changed size during iteration" ; Good atomic copy operations?
From: robert <no-spam@no-spam-no-spam.com>
Date: Sun Mar 12 2006 - 00:55:21 CET
Tim Peters wrote:
> [robert]
Thanks for that details.
---
Looked up copy.py meanwhile:
copy and deepcopy use :
def _copy_dict(x):
return x.copy()
d[types.DictionaryType] = _copy_dict
....
def _deepcopy_dict(x, memo):
y = {}
memo[id(x)] = y
for key, value in x.iteritems():
y[deepcopy(key, memo)] = deepcopy(value, memo)
return y
d[types.DictionaryType] = _deepcopy_dict
Thus deepcopy (but not copy) seems to also expose itself to this
RuntimeError as .iteritems() will iterate on the original dict!
( Would be maybe better to use x.items() here - as it was maybe before
py2.2 )
Its the same Problem as with cPickle.dump. Thus there seems to be no
RuntimeError-save possibility in the standard Python lib to get a
"current view" of an object tree in threaded applications.
Guess it would be more wise to not expose deepcopy, cPickle.dump etc. to
this kind of RuntimeError unnecessarily.
The speed gain of the iterator-method - if any - is minor, compared to
the app crash problems, which are not easy to discover and work-around
(because they happen rarely on fast computers).
Robert
Received on Sun Apr 30 11:36:39 2006
|