[Python-Dev] Pre-PEP: Redesigning extension modules

Antoine Pitrou solipsis at pitrou.net
Sun Sep 1 19:40:48 CEST 2013


On Mon, 2 Sep 2013 00:10:08 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
> 
> $ ./python
> Python 3.4.0a1+ (default:575071257c92+, Aug 25 2013, 00:42:17)
> [GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import atexit
> >>> atexit.register(print, "Hello World!")
> <built-in function print>
> >>> import sys
> >>> del sys.modules["atexit"]
> >>> import atexit as atexit2
> >>> atexit2.register(print, "Goodbye World!")
> <built-in function print>
> >>>
> Goodbye World!

Yeah, atexit is a very particular example, because it interacts with
global state by design (the main interpreter instance), and no amount
of module initialization magic can prevent that :-)

Speaking of which, it also doesn't work (well) with subinterpreters:
http://bugs.python.org/issue18618

Regards

Antoine.


More information about the Python-Dev mailing list