Python cmodules prematurely unloaded?

Stuart I Reynolds S.I.Reynolds at cs.bham.ac.uk
Tue May 25 07:46:02 EDT 1999


Charles G Waldman wrote:
> 
> How about just putting a reference to the C module into the instances
> of the shadow class?
> 
>   import PyGridc #c library functions
> 
>   class MyClass:
>       def __init__(self)
>            ...
>            self.PyGridc = PyGridc
>            ...
> 
> Then the PyGridc module won't be unloaded until all instances of
> MyClass are gone.

This almost worked. I need to make sure I use the local reference to the
modules in the __del__ method:

	def __init__(self):
		self.cstruct=PyGridc.newcstruct(...)

		#Keep reference to module inside class
   		self.PyGridc = PyGridc 

	def __del__(self)
		#Use local reference to module
		self.PyGridc.deletecstruct(self.cstruct)


Cheers,

Stuart




More information about the Python-list mailing list