get_cls_info is not threadsafe
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Storm |
Triaged
|
High
|
Unassigned |
Bug Description
I had got "RuntimeError: dictionary changed size during iteration":
Traceback (most recent call last):
...
File "/app/lib/
find_spec = FindSpec(cls_spec)
File "/app/lib/
info.
File "/app/lib/
cls.
File "/app/lib/
column = getattr(cls, attr, None)
File "/app/lib/
self._cls = _find_descripto
File "/app/lib/
for attr, _descr in cls.__dict_
RuntimeError: dictionary changed size during iteration
storm.info.
I wrote pache:
Index: info.py
=======
--- info.py (rev 5903)
+++ info.py (working)
@@ -19,6 +19,7 @@
# along with this program. If not, see <http://
#
from weakref import ref
+from threading import RLock
from storm.exceptions import ClassInfoError
from storm.expr import Column, Desc, TABLE
@@ -30,7 +31,9 @@
__all__ = ["get_obj_info", "set_obj_info", "get_cls_info",
+_lock = RLock()
+
def get_obj_info(obj):
try:
return obj.__storm_
@@ -50,8 +53,13 @@
# Can't use attribute access here, otherwise subclassing won't work.
return cls.__dict_
else:
- cls.__storm_
- return cls.__storm_
+ _lock.acquire()
+ try:
+ if "__storm_
+ cls.__storm_
+ return cls.__storm_
+ finally:
+ _lock.release()
class ClassInfo(dict):
Changed in storm: | |
status: | New → Triaged |
importance: | Undecided → High |
lock to initialize ClassInfo