On May 11, 2:13 am, Filip Štědronský <[EMAIL PROTECTED]> wrote:
> The main problem are references to objects within a module, because
> we can NEVER be sure there aren't any, even though we cleaned up
> everything, that's just a consequence of Python nature. We can keep
> the old objects referenced and it would make an equivalent to the
> reload() builting, just without loading the module, in effect the
> same as removing it from sys.modules and deleting imported references.
> I do not see any possibe clean way to unload a module...

With the finalizer changes in safethread I think I could pull it off.
Put the module in a cycle, add a weakref to it, remove it from
sys.modules, then run a full collection.  If the weakref clears,
success.  If the weakref doesn't clear, module isn't deleted, readd it
to sys.modules, clean up, and raise an exception.  It won't always
remove the module, but it will do so safely and atomically.

The finalizer changes are necessary as current Python will run __del__
and weakref callbacks as it deletes the module.  It may get
resurrected, get only half done, etc.  Nasty stuff.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to