[Pyrex] Unexpected NameError

Franck Pommereau pommereau at univ-paris12.fr
Thu Nov 22 08:00:37 CET 2007


> 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.

Your absolutely right! I was so much concentrated on the embedding part
that I did not realize that Pyrex is building a module called just as
mine. I simple has a name clash...

> I'll fix this in Pyrex

I'm happy if my mistake could help with improving Pyrex...

> 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()

Very good advice, thanks!

Thank you very much for your help!
Franck



More information about the Pyrex mailing list