Message363402
fyi - we just had a test run into this (in a flaky manner - definitely a race condition) at work:
```
...
for f in inspect.stack(context=0)
File "<embedded stdlib>/inspect.py", line 1499, in stack
return getouterframes(sys._getframe(1), context)
File "<embedded stdlib>/inspect.py", line 1476, in getouterframes
frameinfo = (frame,) + getframeinfo(frame, context)
File "<embedded stdlib>/inspect.py", line 1446, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
File "<embedded stdlib>/inspect.py", line 696, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
File "<embedded stdlib>/inspect.py", line 732, in getmodule
for modname, module in list(sys.modules.items()):
RuntimeError: dictionary changed size during iteration
```
We haven't diagnosed what was leading to it though. Trust in the ability to use inspect.stack() -> ... -> inspect.getmodule() in multithreaded code is on the way out as a workaround.
(this was on 3.6.7)
A workaround we could checkin without consequences should be to change
list(sys.modules.items()) into list(sys.modules.copy().items()).
I was a bit surprised to see this happen at all, list(dict.items()) seems like it should've been done entirely in C with the GIL held the entire time. but maybe I'm just missing where the GIL would be released in the calls to exhause the iterator made by https://github.com/python/cpython/blob/master/Objects/listobject.c ? |
|
Date |
User |
Action |
Args |
2020-03-04 22:57:53 | gregory.p.smith | set | recipients:
+ gregory.p.smith, amaury.forgeotdarc, eric.araujo, meador.inge, python-dev, eric.snow, Erik.Tollerud, serhiy.storchaka, psimons, tomdzk |
2020-03-04 22:57:53 | gregory.p.smith | set | messageid: <1583362673.32.0.468896555576.issue13487@roundup.psfhosted.org> |
2020-03-04 22:57:53 | gregory.p.smith | link | issue13487 messages |
2020-03-04 22:57:53 | gregory.p.smith | create | |
|