various re-import errors
Wed, 13 Apr 1994 15:20:59 +0200

I've received various reports on core dumps and errors caused by
attempts to reload or re-import built-in or dynamically loaded



import foo # where foo is a dynamically loaded module

causes a core dump, at least on systems using SVR4 shared libraries
for dynamic module loading.

import sys
del sys.modules['sys']
import sys

dumps core.


import math

raises ImportError: No module named math


import stdwin
import sys
del sys.modules['stdwin']
import stdwin

does not actually seem to fail but looks very scary because stdwin
cannot be initialized twice in the same process.

In Python version 1.0.1++ (to be released as 1.0.2) I've added the
following checks:

- Calling reload() for dynamically loaded modules (case 1) is
forbidden and raises an ImportError

- Ditto for built-in modules (case 3)

- Attempts to force a reinitialization of a few privileged built-in
modules like sys, __main__ and __builtin__ by deleting them from
sys.modules (case 2) raises ImportError

- Similar attempts for non-privileged built-in modules (case 4) are
not caught. This may still dump core depending on whether the
module's init*() function can be called more than once or not.
(Forbidding this would require more work as it would require
maintaining a table of flags telling whether a particular module was
already initialized.)

- Calling reload() for frozen modules is fixed and should now work as
expected (except I haven't tested it yet :).

--Guido van Rossum, CWI, Amsterdam <>
URL: <>