[Python-Dev] Fix import errors to have data (original) (raw)

Christian Tismer tismer at stackless.com
Sun Aug 1 02🔞48 CEST 2004


Guido van Rossum wrote:

It's going to be difficult to ensure that nothing ever gets a reference to a broken module, because of circular imports. Suppose A imports B, which imports A. If A's initialisation subsequently fails, then even if A is removed from sys.modules, B still contains a reference to the broken A.

Well, circular imports first appeared to me like the reverse problem of circular references. The latter was only solvable by a garbage collector. Well, it's simpler after all.

Circular imports, to be made consistent, would need something like a final "commit" after all imports succeeded. I think of a simple, generator-like "undoable assignment" to sys.modules, like ICON's "<-" operator. When a top-level import starts, the module gets into sys.modules, but this is also recorded as not finished. Further imports can happen, until this is all done. Then, the pending undos are cancelled, this is the "commit". If any uncaught exception occours, the latent undo is executed for all imports started in this context, and we end up with an exception and (hopefully) almost no side effects. Maybe this could be user-extensible, as on-failure-undo actions.

Yeah, but I don't mind; my patch is still a big improvement in other cases and doesn't really make things any worse in the above case (B has a reference to a broken A, just like without my patch).

It is definately an improvement, much more at what people would expect, anyway.

Did anybody look at my patch? Shall I check it in?

Yes I did.

+1

-- Christian Tismer :^) <mailto:tismer at stackless.com> Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : Starship http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 mobile +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/



More information about the Python-Dev mailing list