[Pyrex] Re: Globals and wrapping Eiffel

Bob Ippolito bob at redivi.com
Wed Nov 19 21:18:44 CET 2003


On Nov 19, 2003, at 3:09 PM, Godefroid Chapelle wrote:

> Andreas Kostyrka wrote:
>> On Wed, Nov 19, 2003 at 03:31:18PM +0100, Godefroid Chapelle wrote:
>>> This was the question I wanted to ask : is there a way in Pyrex to
>>> declare some code that must run once when the extension module is 
>>> imported ?
>> Does this answer your question:
>
> Yes, thanks
>> Python 2.3 (#2, Sep  8 2003, 13:25:25)
>> [GCC 2.95.3 20010315 (SuSE)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import t
>> hello
>>>>> import t
>>>>> import t
>>>>> import t
>>>>> del t
>>>>> import t
>>>>> print open("t.pyx").read()
>> print "hello"
> The only thing I am not sure about is this one :
> I suppose that the del statement just erases the 't' name from the 
> namespace while keeping the module loaded

Modules don't get unloaded until their reference count goes to zero.  
"import t" makes two references to t, one in sys.modules and one in the 
namespace you import it from.  Modules never leave sys.modules 
implicitly, you have to do that on purpose, which isn't always a good 
idea -- especially for extension modules.  For example, the interpreter 
will crash if you unload an extension module containing Objective C 
code (on OS X, at least).  pydoc is the only "deletes stuff from 
sys.modules" offender that I'm aware of, but there are surely others.

-bob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20031119/088d21b3/smime.bin


More information about the Pyrex mailing list