New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: dictionary changed size during iteration #18
Comments
I also encountered this error. |
Have the same issue - did you find a work around? |
Good catch. I agree with @zkkzhangkangkang's static analysis, The reason then must be that the parent node being looked up by For testing, do any of you have a minimal working example, or a public project, that reproduces the bug? This would help me see why the parent node isn't getting defined. As a fallback solution, it is possible to postpone the update of def get_node(..., stash=None):
...
target = stash or self.nodes
if name in target:
target[name].append(n)
else:
target[name] = [n]
return n
...
def collapse_inner(...):
stash = {}
def unstash():
nonlocal stash
for name in stash:
if name in self.nodes:
self.nodes[name].extend(stash[name])
# TODO: probably need to drop duplicates - list(set(...))?
else:
self.nodes[name] = stash[name]
stash = {}
handled = set()
while True:
for name in self.nodes:
if name in ('lambda', 'listcomp', 'setcomp', 'dictcomp', 'genexpr'):
for n in self.nodes[name]:
if n not in handled:
....
# use the stash option here
handled.add(n)
if not stash:
break
unstash() |
@Technologicat, I was using a large DNN code base, but here is one minimal set that causes this. It seems a combination of Notes: command and output:
|
Another, more legitimate example that is equally nonsensical, but is structured correctly. Same issue. |
@pliablepixels As you may have guessed, I'm busy right now, but I'll have a look as soon as I have time. Having an example that reproduces the bug should make this much easier. Thanks for the MWE! |
It looks like this PR fixes the issue: https://github.com/Technologicat/pyan/pull/24/files |
Yes, it should work now. ( |
Getting this on a specific directory (not seeing it elsewhere)
What do you need to dig into this?
Traceback (most recent call last):
File "/Users/nevep/.pyenv/bin/versions/3.7.4/envs/egs-api/bin/pyan3", line 7, in
exec(compile(f.read(), file, 'exec'))
File "/Users/nevep/bepress/pyan/pyan3", line 11, in
sys.exit(main())
File "/Users/nevep/bepress/pyan/pyan/main.py", line 109, in main
v = CallGraphVisitor(filenames, logger)
File "/Users/nevep/bepress/pyan/pyan/analyzer.py", line 77, in init
self.process()
File "/Users/nevep/bepress/pyan/pyan/analyzer.py", line 87, in process
self.postprocess()
File "/Users/nevep/bepress/pyan/pyan/analyzer.py", line 154, in postprocess
self.collapse_inner()
File "/Users/nevep/bepress/pyan/pyan/analyzer.py", line 1562, in collapse_inner
for name in self.nodes:
RuntimeError: dictionary changed size during iteration
The text was updated successfully, but these errors were encountered: