[Zope] Globals disappearing in extmethod?

Dieter Maurer dieter@handshake.de
Mon, 4 Feb 2002 23:20:22 +0100


Joseph A Knapka writes:
 > ...
 > (1) Defines an external method for processing form data:
 > 
 > # In module MyModule:
 > def myExtMethod(req):
 > 
 >     global Request
 >     Request = req
 > 
 >     action = getFormData("action")
 >     #...process request...
 > ...
 > Now the problem. This code works most of the time.
 > However, apparently at random, when executing
 > a request, I will get an exception from getFormData():
 > "global name Request does not exist." This is very
 > strange, because /every/ invocation of getFormData()
 > is called from myExtMethod(), so there's simply no way
 > the Request global can be unset, as far as I can see.
In earlier Zope versions (may no longer be true for very new
Zope versions (i.e. above 2,4,3)), the source files
of External Methods have not been Python modules.
Their data was thread private. I.e. each of the Zope threads
had its own copy of this data (and of your global
variable "REQUEST"). When a new thread processes the request,
it may not see the global variable defined in a previous
request.

Move such data into a true Python module, define your function
there. Make you External Method a one liner:

       from myTruePythonMethod import myFunction


Dieter