[Python-bugs-list] [ python-Bugs-698282 ] __file__ attribute missing from dynamicly loaded module

SourceForge.net noreply at sourceforge.net
Mon Aug 25 12:04:50 EDT 2003


Bugs item #698282, was opened at 2003-03-05 15:52
Message generated for change (Comment added) made by shacktoms
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=698282&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: David C. Sweeton (dsweeton)
Assigned to: Nobody/Anonymous (nobody)
Summary: __file__ attribute missing from dynamicly loaded module

Initial Comment:
Only the first instanceof a dynamically loaded module 
gets the __file__ attribute. It is missing from all later 
instances.

The problem is in importdl.c in the function 
_PyImport_LoadDynamicModule. The first time a 
module is loaded a copy of its module dictionary is 
made by a call to _PyImport_FixupExtension. After that 
copy was made, _PyImport_LoadDynamicModule adds 
the _file__ attribute to the original module dictionary. 
Thus the first instance of the module has the 
__file__attribute.

Later when another instance of the module loads, its 
module dictionary is duplicated from the copy of the 
dictionary from the first instance. The problem is that 
when that copy was made, the __file__ attribute was not 
yet there. Thus the later instance of the module does 
not have the __file__ attribute.

The required fix is in importdl.c and consists of simply 
moving the call of _PyImport_FixupExtension to a point 
just after the __file__ attribute is added, instead of just 
before it. I have tested this fix and it solves the problem.


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

Comment By: Shack Toms (shacktoms)
Date: 2003-08-25 14:04

Message:
Logged In: YES 
user_id=603293

This only appears to be a problem when embedding multiple 
python interpreters in a single application, when more than 
one interpreter does an import that refers to the __file__ 
attribute.   Maybe this would also be a problem for the 
Apache mod_python?  In any case, I have a cdiff file based 
on revision 2.70 of importdl.c.   I hope it can be incorporated.

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

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



More information about the Python-bugs-list mailing list