[Zope] Re: Global variables in ExternalMethod modules

Tres Seaver tseaver at zope.com
Tue Feb 1 13:06:17 EST 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ben Last wrote:

|> If this *were* a true module (see below), you would not be getting
|> per-thread semantics from it;  you would need to keep a mapping keyed by
|> thread ID to get such semantics.
|
| I'd been told a while back that "each Zope thread has its own namespaces
| and therefore its own copy of any given module-level variable".  Is this
| false (given what you say below about ExternalMethod implementations not
| being real modules)?

Persistent objects are held in per-thread caches;  module-level stuff is
~ *not* part of that cache.  People sometimes fake out thread-level
caches by assigning "volatile" attributes to persistent objects
(attributes whose names start with '_v_');  the downside is that such
attributes go away whenever the persistent object is "ghostified", which
may occur at unpredictable times (e.g., at transaction or subtransaction
boundaries).

|> The files containing ExternalMethod implementations are not "modules",
|> really, and so your expectations about module-level globals are not
|> being met.  Instead, the EM machinery "execs" the text of the EM file in
|> a custom namespacee, and then extracts the code object from it.
|>
|> I think you are headed into "build a product" territory here, unless you
|> want your EM to monkey-patch its cache into an existing module somewhere.
|
| Ouch.  "Build a product" isn't an option for us, for a whole bunch of
| reasons.  I guess one way to deal with this, then, would be to put the
| module-level objects in *another* module and import *that*?
|
| Does each Zope thread get its own copy of an imported module, or would I
| need to use something like Dieter's SharedResource to keep, say, a dict
| of connections keyed by thread id?

Threads which use "normal" import statements (rather than hacking around
with '__import__') won't have separate copies of Python modules.  I
don't know that product, but it sounds like it might be what you need.

Remind me again what you need a per-thread cache for?  Could you
scribble on the REQUEST object instead?

Tres.
- --
===============================================================
Tres Seaver                                tseaver at zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFB/8UZGqWXf00rNCgRAkdzAJ4/qFY6fMLFn82s+gWl9PVGh3OjGACdEcpH
BCjKHO/frTyksThe+y7EMQU=
=PL45
-----END PGP SIGNATURE-----


More information about the Zope mailing list