Python cmodules prematurely unloaded?

Stuart I Reynolds S.I.Reynolds at cs.bham.ac.uk
Mon May 24 12:52:30 EDT 1999


Hi,

I'm writing Python wrappers for some C code I have. I've come across a
problem which seems to be due to Python unloading modules before I'm
finished with them:

--------------
import PyGridc #c library functions

class MyClass:
    def __init__(self)
        ...

	#datacstruct assumes ownership of
	#data, calling INCREF
	self.datacstruct = PyGridc.newGridData( ..some objects.. )

    def __del__(self):
	print '>>>>>>>>>'
	print PyGridc

	#Calls DECREF for stored data in struct
	PyGridc.deleteGridData(self.datacstruct)
	print '<<<<<<<'

g = MyClass()
del g
------------


All works fine if I keep the "del g" line. However, if I remove just
that line and let Python delete it. I get:

%>>>>>>>>>
%None
%Exception exceptions.AttributeError: "'None' object has no attribute
%'deleteGridData'" in <method MyClass.__del__ of MyClass instance at
%b9d68> ignored

Instead of:
%>>>>>>>>>
%<module 'PyGridc' from './PyGridcmodule.so'>
%<<<<<<<

Note that printing out the module produces None. Has the module been
prematurely unloaded? If so why and how can I stop it so that I can
safely delete the contents of my C struct.

Cheers,

Stuart




More information about the Python-list mailing list