From da5e847b63a2ec25a7fcc19c976370879f028f84 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sat, 28 Jun 2014 07:03:31 +0300 Subject: [PATCH] Fix RuntimeError in gunicorn.reloader. Here's the reproducer in Python 3.3: $ gunicorn --paste paste.ini --reload Then I got the following exception: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/local/lib/python3.3/threading.py", line 901, in _bootstrap_inner self.run() File "/home/berker/hacking/mediagoblin/venv3/lib/python3.3/site-packages/gunicorn/reloader.py", line 41, in run for filename in self.get_files(): File "/home/berker/hacking/mediagoblin/venv3/lib/python3.3/site-packages/gunicorn/reloader.py", line 29, in get_files for module in sys.modules.values() File "/home/berker/hacking/mediagoblin/venv3/lib/python3.3/site-packages/gunicorn/reloader.py", line 28, in re.sub('py[co]$', 'py', module.__file__) RuntimeError: dictionary changed size during iteration --- gunicorn/reloader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gunicorn/reloader.py b/gunicorn/reloader.py index 219ffa835..130e3d60a 100644 --- a/gunicorn/reloader.py +++ b/gunicorn/reloader.py @@ -26,7 +26,7 @@ def add_extra_file(self, filename): def get_files(self): fnames = [ re.sub('py[co]$', 'py', module.__file__) - for module in sys.modules.values() + for module in list(sys.modules.values()) if hasattr(module, '__file__') ]