[Zope] Globals disappearing in extmethod?

Joseph A Knapka jknapka@earthlink.net
Mon, 04 Feb 2002 23:25:13 +0000


Dieter Maurer wrote:
> 
> 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

Hmm... I think my external method is already a Python module,
since I had to tell it the module name and function when
I did "Add->External Method." This is under Zope 2.5.0 on
Windows (NT development system, production server will
be Win98 -- Yes, I know, but I'm stuck with it.)

I'll try your suggestion and see if it helps.

Thanks,

-- Joe
"I should like to close this book by sticking out any part of my neck
 which is not yet exposed, and making a few predictions about how the
 problem of quantum gravity will in the end be solved."
 --- Physicist Lee Smolin, "Three Roads to Quantum Gravity"