[Zope] Globals disappearing in extmethod?

Joseph A Knapka jknapka@earthlink.net
Mon, 04 Feb 2002 12:21:49 +0000


"Thomas B. Passin" wrote:
> 
> You need to declare "global Request' in the definition of getFormData(),
> too.

No. In Python, the rule is "any variable not assigned in the body
of a function is presumed to be a module global" (though this may
change in the presence of nested scopes in Python 2.2).

It appears that global state in Zope is just not handled the way I,
as a Python programmer, expect. For example:

# In module xtest:
myVar = 0

# External method:
def getAndIncMyVar():
  global myVar
  myVar = myVar + 1
  return "The value of myVar is now %d"%myVar

# In DTML document myVarTest:
<standard_html_header>
<dtml-var expr="getAndIncMyVar()">
<standard_html_footer>

If you go to the /myVarTest URL and hit "Refresh Page"
a couple of dozen times, you will see the reported
value of myVar jump around. It will increase for a
while, then jump backward an apparently random number.
The violates my (Python-centered) expectations
most horribly, and I'd really like to understand it.

Are external-method modules automaically reloaded
periodically, or something like that?

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"