This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author twouters
Recipients twouters
Date 2012-08-07.20:50:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1344372630.36.0.657008264392.issue15578@psf.upfronthosting.co.za>
In-reply-to
Content
In a submodule of a package, replacing the parent package in sys.modules during import of the package (meaning the only reference to it is in sys.modules) and then importing itself (or something from itself) crashes the interpreter:

centurion:~/python/crasher > cat sa/__init__.py
import v1
centurion:~/python/crasher > cat sa/v1/__init__.py
import sys
sys.modules['sa'] = sys.modules[__name__]
import sa
centurion:~/python/crasher > python -c 'import sa'
Segmentation fault (core dumped)

It seems the crash is not entirely deterministic, as we've had the original code this was reduced from run in Python 2.4 and 2.6 for years, and only discovered the crash when switching to 2.7. However, running the reduced testcase crashes for me in all of Python 2.7, 2.6, 2.4 and 2.2, in debug builds and opt builds. Given the nature of the bug I expect debug builds to crash reliably.

I haven't found the actual source of the problem, but what seems to happen is that the import mechanism has a borrowed reference to the 'sa' module around, assuming it'll stay alive while the submodules are imported because it's also stored in sys.modules. This assumption is incorrect. However, changing the import in sa/__init__.py into an absolute or explicit relative import seems to fix the problem, which means this probably won't affect Python 3.
History
Date User Action Args
2012-08-07 20:50:30twouterssetrecipients: + twouters
2012-08-07 20:50:30twouterssetmessageid: <1344372630.36.0.657008264392.issue15578@psf.upfronthosting.co.za>
2012-08-07 20:50:29twouterslinkissue15578 messages
2012-08-07 20:50:28twouterscreate