[Zope-Perl] Re: perlmod.py

Gisle Aas gisle@ActiveState.com
04 Mar 2001 23:15:56 -0800


"DNA" <dna@agmweb.ca> writes:

> Just added in perl into one of my Zope products... very cool. Found that the
> caching perl_require doesn't seem to work to well from Zope, it would fail
> after the first time, so I commented out and it works fine. I'll see if can
> find a way around that, just thought you might like to know...

Thanks for spotting this!  This obviously need some more though.  The
problem is that the INC dict needs to be made thread specific (if
perl.MULTI_PERL) because we have separate Perl interpreters's for each
thread.

Something like this should work (I hope):

> def perl_require(mod):
>     # Some caching since the real 'perl.require' is a bit
>     # heavy.
> #    global INC
> #    try:
> #        return INC[mod]

           return INC[thread.get_ident()][mod]

> #    except KeyError:
> #        pass
> 
>     import perl

      if not INC.has_key(thread.get_ident()):
           INC[thread.get_ident()] = {}

>     INC[mod] = perl.require(mod)

      INC[thread.get_ident()][mod] = perl.require(mod)

>     return INC[mod]

And then the perl_require-code should be tweaked so that it works even
when the thread module is not present.  I'll make you a real patch
tomorrow.

--Gisle