[Python-bugs-list] [ python-Bugs-478421 ] cPickle bug when using imp.load_source()

noreply@sourceforge.net noreply@sourceforge.net
Mon, 12 Nov 2001 04:02:39 -0800


Bugs item #478421, was opened at 2001-11-05 12:12
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=478421&group_id=5470

Category: Python Library
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Andrew R Gross (sincere2001)
Assigned to: Nobody/Anonymous (nobody)
Summary: cPickle bug when using imp.load_source()

Initial Comment:
When a Python 2.1.1 program dynamically creates a
module using
the 'imp.load_source()' function, and the created
module tries to 
'import cPickle', the interpreter dies with a
SystemError exception:

SystemError: _PyImport_FixupExtension: module
import_cPickle.cPickle not loaded

This does *not* occur when the find/load_module()
functions are used.

The bug also appears to have been introduced somewhere
in 2.x,
as 1.5.x works fine with load_source().

Attached is a full explanation of the behavior and some
small
sample programs to illustrate the bug.



----------------------------------------------------------------------

Comment By: Simo Salminen (frangen)
Date: 2001-11-12 04:02

Message:
Logged In: YES 
user_id=291461

Your example works fine with my system. However:
You are giving imp.load_source bad 'name' paramater. In 
your example:
mod2 = imp.load_source(file, file, open(file))
Change that first paramater to os.path.splitext(file)[0] 
and it might work.

Here is an example program that shows how load_source fails 
with bad first paramater:

egg.py:
import imp
imp.load_source('spam.py', 'spam.py', open('spam.py'))

spam.py:
import os.path

% python egg.py
ImportError: No module named path

and now fix that egg.py file:
imp.load_source('spam', 'spam.py', open('spam.py'))

-> works fine. (tested with activepython 2.1.1)

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=478421&group_id=5470