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.

classification
Title: __file__ attribute missing from dynamicly loaded module
Type: Stage:
Components: Interpreter Core Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dsweeton, loewis, shacktoms
Priority: normal Keywords:

Created on 2003-03-05 20:52 by dsweeton, last changed 2022-04-10 16:07 by admin. This issue is now closed.

Messages (3)
msg14987 - (view) Author: David C. Sweeton (dsweeton) Date: 2003-03-05 20:52
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.
msg14988 - (view) Author: Shack Toms (shacktoms) Date: 2003-08-25 18:04
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.
msg14989 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-09-04 18:48
Logged In: YES 
user_id=21627

This is fixed with patch 794826, in importdl.c  2.71 and
2.70.14.1, NEWS 1.831.4.31.
History
Date User Action Args
2022-04-10 16:07:24adminsetgithub: 38109
2003-03-05 20:52:29dsweetoncreate