jparise / python-reloader

Dependency-based Python Module Reloader
http://www.indelible.org/ink/python-reloading/
MIT License
135 stars 27 forks source link

Doesn't seem to work as advertised #4

Closed dabrahams closed 13 years ago

dabrahams commented 13 years ago

this tree contains a tiny prototype project that demonstrates. Check it out, and type python master.cfg in that directory. The output I'm getting is as follows:

** loading /Users/dave/src/bbproto/master.py as master
** loading /Users/dave/src/bbproto/submodule/__init__.py as submodule
** loading /Users/dave/src/bbproto/submodule/main.py as submodule.main
{'master': [<module 'submodule' from '/Users/dave/src/bbproto/submodule/__init__.py'>,
            <module 'submodule' from '/Users/dave/src/bbproto/submodule/__init__.py'>],
 'pprint': [<module 'cStringIO' from '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/cStringIO.so'>]}
*********** RELOADING **********
** loading /Users/dave/src/bbproto/submodule/__init__.pyc as submodule
** loading /Users/dave/src/bbproto/master.pyc as master

Note that the submodule module gets reloaded, but submodule.main does not.

dabrahams commented 13 years ago

The problems run deep and wide on this one. I'm trying to fix it now. This module sorely needs tests!

dabrahams commented 13 years ago

Actually I'm beginning to think that this approach is hopelessly unworkable in general, even after you fix it to deal properly with the arguments to the builtin __import__. The problem is that there are circular imports. Really, you need to release the entire subgraph rooted at the thing being reloaded. Lots more detail on this in: http://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module

So, I'm just sayin', don't count on me for a fix. Sorry!

dabrahams commented 13 years ago

The first 44 lines of this module seem to actually be working for me. I don't know whether it's general enough to be considered a solution to the problem you're trying to address.

dabrahams commented 13 years ago

My more general solution is here, and I won't post anything more to this ticket. Cheers!