[Python-3000] Is reload() feasible?
Ian Bicking
ianb at colorstudy.com
Thu Apr 13 20:39:43 CEST 2006
In another thread ("Module Initialization and finalization") reload()
has come up, and some suggestions to improve the reloadability of modules.
I would like to ask: is reloading feasible at all? Right now reload()
works poorly. The builtin reload() can be improved some, but there are
problems that cannot ever be resolved in general. For instance, generic
functions involve a central registry; reloading a module will reload any
registrations. This can probably be handled, though I suspect special
code for this condition will be required. Reloading the model function
(damn, we need more names for this stuff -- the original function that
contains the the registry) will lose all the registrations, and I don't
see a good way to resolve that. Reloading a module that removes a
registration that was previously there is also hard to handle.
This is just for one example, these kinds of problems are all over the
place. Notably, Zope 3 does not include reloading (though it was
included in Zope 2, in a more general form than just what reload()
does). It was removed because of these corner cases where it doesn't
work, and because when these corner cases happen the results are
inscrutable and frustrating errors.
To focus energy I think we should give up on reloading. At the same
time, long running processes that require manual restarts just *feel*
really uncomfortable. It's like a compile step. So the underlying
problem shouldn't be ignored.
I would propose that light, disposable interpreters are a better way of
handling the problem. When a file changes, you throw away the
interpreter and start over. Several projects are doing this now, but
making it more standardized would be very helpful to improving the
usability of the technique.
For interactive environments some of the same issues apply, though the
resolution is more difficult. Can you safely re-evaluate the entire
history and get to the same state that you started at? You can imagine
using restart() at the interactive prompt, and having the process die,
restart, run the entire history (showing output?) and leaving you with a
potentially equivalent environment. Replaying history also might fail,
or have side effects that cannot or should not be repeated. So, a
restart strategy opens up lots of questions; but I think abandoning
reload() would better bring those questions into focus.
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Python-3000
mailing list