homepage

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 eudoxos
Recipients eudoxos
Date 2012年10月11日.11:11:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1349953870.22.0.50760531633.issue16194@psf.upfronthosting.co.za>
In-reply-to
Content
I have several compiled modules linked into one .so file and import them using imp.load_dynamic.
Only the first module imported with load_dynamic is imported properly, all subsequent calls of load_dynamic on the same file ignore the first argument (name) and return the first module again. The init function is also called only for the first module imported by load_dynamic.
The bug is reproducible for python 2.7.3 and 3.2.2. Test case is attached.
Here inline simplified source for 2.7:
foo.c:
	#include<stdio.h>
	#include<Python.h>
	PyMODINIT_FUNC initfoo(){
		(void) Py_InitModule("foo",NULL);
		printf("initfoo()\n");
	}
	PyMODINIT_FUNC initbar(void){
		(void) Py_InitModule("bar",NULL);
		printf("initbar()\n");
	}
	PyMODINIT_FUNC initbaz(void){
		(void) Py_InitModule("baz",NULL);
		printf("initbaz()\n");
	}
test.py:
	import sys,imp
	# import foo using the normal machinery
	sys.path.append('.')
	import foo
	# this is OK
	print imp.load_dynamic('bar','foo.so')
	# this imports *bar* again, but should import baz
	print imp.load_dynamic('baz','foo.so')
	# this imports *bar* again, although the module is not defined at all
	print imp.load_dynamic('nonsense','foo.so')
Compiled with
 gcc -shared -fPIC foo.c -o foo.so `pkg-config python --cflags --libs`
I get when running "python test.py" output:
 initfoo()
 initbar()
 <module 'bar' from 'foo.so'>
 <module 'bar' from 'foo.so'>
 <module 'bar' from 'foo.so'>
The module 'bar' is imported 3 times, although the 2nd import should import *baz* and the third import should fail ("nonsense" module does not exist).
History
Date User Action Args
2012年10月11日 11:11:10eudoxossetrecipients: + eudoxos
2012年10月11日 11:11:10eudoxossetmessageid: <1349953870.22.0.50760531633.issue16194@psf.upfronthosting.co.za>
2012年10月11日 11:11:10eudoxoslinkissue16194 messages
2012年10月11日 11:11:09eudoxoscreate

AltStyle によって変換されたページ (->オリジナル) /