[mod_python] How to globalize vars ???

fowlertrainer at anonym.hu fowlertrainer at anonym.hu
Fri Jan 9 16:19:41 EST 2004


Hello !

I have get a strange problem in mod_python site.
More modules I have, and think, to I initialize my Session handler
from main module.

Like this:

-- main --

import BHASession

# Session info
BHASessionDir="C:/bhaweb/sessions"
#f=open("c:/now.txt","a");f.write(" 1");f.close();
BHASession.SSInit(BHASessionDir)
#f=open("c:/now.txt","a");f.write(" 2");f.close();

-- Session --
f=open("c:/now.txt","a");f.write(" 01");f.close();
#global SSDefaultDir
SSDefaultDir="c:/bhaweb/sessions"
f=open("c:/now.txt","a");f.write(" 02");f.close();
SSLockObj=threading.Lock()

def SSLock():
    SSLockObj.acquire()

def SSUnlock():
    SSLockObj.release()

def SSInit(SessionDir):
    #f=open("c:/now.txt","a");f.write(" 03");f.close();
    SSLock()
    try:
      #global SSDefaultDir
      #r.append(str(SSDefaultDir))
      #f=open("c:/now.txt","a")
      #f.write(" "+SSDefaultDir)
      #f.close()
      #r.append(str(SSInitialized))
      if SSDefaultDir.strip()=="":
#       <-
# UnboundLocalError: local variable 'SSDefaultDir' referenced before assignment
         r.append(str(SSDefaultDir))
         SSDefaultDir=SessionDir
         f=open("c:/now.txt","a")
         f.write(" "+SSDefaultDir)
         f.close()
    finally:
      SSUnlock()

--------------
      
When I not use SSInit, only I write the global variable in BHASession
module like this:

SSDefaultDir="c:/bhaweb/sessions"

then it is working good !!!

Why ? How to force python to module see his variable ?

Thanx for any advance  !

-- 
Best regards,
 fowlertrainer                          mailto:fowlertrainer at anonym.hu



More information about the Mod_python mailing list