defnull/bottle — Issue #275: reloader: RuntimeError in thread due to 'dict. size change' (+ workaround)
Author: appultaart
Created: 2012-01-29 21:11:47+00:00
State: open

(Disclaimer: (1)Just starting out with Bottle framework, in attempt to create simple, web-based access to local database, and (2) no professional Python coder.)

Issue: When I enable the auto-reloader with the "run(reloader=True)" command on my Ubuntu box (2.6.32-38, 64bit):

with Python 2.6: all works as expected
with Python 3.2.2: a RuntimeError appears, and the auto-reloader obviously does not start. Here's the error:

> Exception in thread Thread-1:
> Traceback (most recent call last):
> File "/home/me/programs/Python-3.2.2/lib/python3.2/threading.py", line 740, in _bootstrap_inner
> self.run()
> File "/home/me/python/bottle_webFramework/myScripts/bottle.py", line 2507, in run
> for module in sys.modules.values():
> RuntimeError: dictionary changed size during iteration

Error can be solved (and functional reloader obtained, as expected), by explicitly declaring as a list in lines 2507 and 2517, but this is probably a dirty workaround only (I'm not familiar with system level thread checks...):

@ 2507
--- for module in sys.modules.values():
+++ for module in list(sys.modules.values()):

@ 2517
--- for path, lmtime in files.items():
+++ for path, lmtime in list(files.items()):

Hope this helps,
thanks for a nice, simple webframework!