Skip to content
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

Fix RuntimeError: dictionary changed size during iteration #85

Merged
merged 2 commits into from Jan 12, 2021

Conversation

joemeister
Copy link
Contributor

@joemeister joemeister commented Jan 12, 2021

Description

This attempts to address situations where globals() changed during iteration.

    import httpagentparser
  File "/.virtualenv/lib/python3.6/site-packages/httpagentparser/__init__.py", line 647, in <module>
    detectorshub = DetectorsHub()
  File "/.virtualenv/lib/python3.6/site-packages/httpagentparser/__init__.py", line 21, in __init__
    self.registerDetectors()
  File "/.virtualenv/lib/python3.6/site-packages/httpagentparser/__init__.py", line 34, in registerDetectors
    detectors = [v() for v in globals().values() if DetectorBase in getattr(v, '__mro__', [])]
  File "/.virtualenv/lib/python3.6/site-packages/httpagentparser/__init__.py", line 34, in <listcomp>
    detectors = [v() for v in globals().values() if DetectorBase in getattr(v, '__mro__', [])]
RuntimeError: dictionary changed size during iteration

It occurred during start up of a multi-threaded Flask app.

Approach

Iterate a list copy of globals().values() instead.

@sfdye
Copy link

sfdye commented Jan 12, 2021

@shon what do you think?

@shon shon merged commit c08bacd into shon:master Jan 12, 2021
@shon
Copy link
Owner

shon commented Jan 12, 2021

Thank you @sfdye

@sfdye
Copy link

sfdye commented Jan 12, 2021

While I have you, any chance we can cut a new release that includes this fix? Because our production is currently affected by the bug. Please let me know if you need any help with the chores.

shon added a commit that referenced this pull request Jan 12, 2021
@shon
Copy link
Owner

shon commented Jan 12, 2021

@sfdye
Copy link

sfdye commented Jan 12, 2021

Wow you are amazing 🤩 thank you!

shon added a commit that referenced this pull request Jan 12, 2021
@shon
Copy link
Owner

shon commented Jan 12, 2021

@sfdye sorry here's the correct link https://pypi.org/project/httpagentparser/1.9.1/

@joemeister
Copy link
Contributor Author

Thanks for the speedy response @shon !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants