Sorry, again: Module Loading Problem

F

fowlertrainer

Hello !

I have used mod_python. But it is don't reload my modules when I
editing them.

I try with this:
--------------------
# Module importer
import os
import traceback
import kinterbasdb
import sys
import time
import threading
import imp
import stat

ImpLock=threading.Lock()
IModuleDir="C:/bhaweb/modules"
IModules={}

def LoadModule(ModName):
fp, pathname, description = imp.find_module(ModName)
try:
mod=imp.load_module(ModName, fp, pathname, description)
print mod
sys.modules[ModName]=mod
finally:
# Since we may exit via an exception, close fp explicitly.
if fp: fp.close()

def ImportModules(Modules):
ImpLock.acquire()
try:
if not (IModuleDir in sys.path): sys.path.append(IModuleDir)
# Do imports, if needed
print Modules
for m in Modules:
sf=IModuleDir+"/"+m+".py"
if sys.modules.has_key(m):
sd=os.stat(sf)
lm=sd[stat.ST_MTIME]
if IModules.has_key(m):
dd=IModules[m]
if (dd<>lm):
print "ReLoad"
reload(sys.modules[m])
IModules[m]=lm
else:
print "Load"
LoadModule(m)
sd=os.stat(sf)
lm=sd[stat.ST_MTIME]
IModules[m]=lm
'''
import s
sf=IModuleDir+"/"+s


'''
print IModules
finally:
ImpLock.release()

#for k in sys.modules.keys(): print k,sys.modules[k]
'''
f=file(IModuleDir+"/test.py","w")
f.write("print 1")
f.close()
'''
#print os.stat(IModuleDir+"/test.py")[stat.ST_MTIME]
#sys.exit()
'''
ImportModules(["test"])
f=file(IModuleDir+"/test.py","w")
f.write("print 2")
f.close()
time.sleep(2)
ImportModules(["test"])
'''
ImportModules(["test"])
test.test()
--------------------
test.py is this:
def test():
print 1
--------------------
But python is say:
Executing: C:\Program Files\ConTEXT\ConExec.exe
"C:\Python\python.exe" "C:\bhaweb\modules\ModImport.py"

['test']
Load
<module 'test' from 'C:\bhaweb\modules\test.pyc'>
{'test': 1073316581}
Traceback (most recent call last):
File "C:\bhaweb\modules\ModImport.py", line 75, in ?
test.test()
NameError: name 'test' is not defined
Execution finished.

I run this in native mode, but do this in under mod_apache also.

Why ? What I do wrong ?
Plase send the email in private also, because I'm in digest mode.

Thanx:
KK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top