unload/delete modules

Sebastien de Menten sdementen at hotmail.com
Wed Feb 12 14:48:45 CET 2003


Jp Calderone <exarkun at intarweb.us> wrote in message news:<mailman.1044995379.6060.python-list at python.org>...
> On Tue, Feb 11, 2003 at 06:47:20AM -0800, Sebastien de Menten wrote:
> > Hi,
> > 
> > I have done some research on the topic but it is still very fuzzy...
> > 
> > I have the following script
> > 
> > for i in range(5):
> > 	create module foo with function run that print i(i)
> > 	import foo
> > 	foo.run()
> > 
> > The function "create module foo with function run that print i(i)" :
> >  - write a .pyx file (Pyrex file), with code for printing the argument
> > i
> >  - translate the file with Pyrex in c code
> >  - compile the c code to get a foo.so module.
> > 
> 
>   There is no platform-independant way to unload shared object libraries
> (even doing it correctly on different releases of the same platform can be a
> challenge), and so Python makes absolutely zero attempt to have reload()
> work on .so modules.
> 
> > [snip]
> > Is there a solution for my problem ?
> 
>   I'm not sure you've told us your problem ;)  You have told us one solution
> you've selected to your problem, and the problems that *it* has, though.  So
> I think I can say that there is no solution to this solution.  Maybe you can
> tell us the real problem you're trying to address, and we can all try and
> come up with a different solution.
> 
> 

The problem is performance...
Basically, i need to run a code that looks like this

for i in range(S):
	x = 0
	for i in range(T):
		x += A*x + b
	do_some_more_stuff_with(x)

where
 - A is an array of size NxN
 - b is a vector of size N
 - x is a vector of size N
 - S and T ~ 10000
 - N ~ 10
and the operations =,+= and + are vector based and * is the
matrix-vector multiplication

I can't do it in python as it is too slow so I must write it in C and
call it from Python. The additional characteristic is that A is very
sparse and taking that into account can increase performance by 20 on
a simple example.

Hence, I want to generate the code for "x += A*x + b" on the fly for a
given matrix A and vector b (known when generating the code). I do
this by generating Pyrex code and loading the module Pyrex creates.

However, if I modify A or b and regenerate a module, I can't load it
anymore as the module is already imported!

... any thoughts




More information about the Python-list mailing list