[Pyrex] Unexpected NameError
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed Nov 21 11:01:02 CET 2007
Franck Pommereau wrote:
> Here is the faulty code.
I think I've figured out what's going on. It seems that
Py_InitModule4 returns a borrowed reference to the module,
and Pyrex doesn't incref it, so it's relying on the entry
in sys.modules to keep it alive. But snakes.plugins.load()
replaces the 'snk' module, so it disappears out from under
the Pyrex code that's using it. It's no wonder you were
getting weird things happening.
I'll fix this in Pyrex, but in the situation you have
here, are you sure you really want to replace the module
rather than just updating the existing one with extra
entries? Replacing a module that's in use doesn't seem
like a very good idea to me.
By the way, while investigating this, I also noticed another
potential problem with your code -- if any exceptions occur
during the module init code of snk, you won't notice them.
You can fix this by declaring initsnk as
cdef extern void initsnk() except *
and catching exceptions when you call it in snk_initialize,
e.g.
try:
initsnk()
except:
import traceback
traceback.print_exc()
--
Greg
More information about the Pyrex
mailing list