Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Sorry, again: Module Loading Problem

Reply
Thread Tools

Sorry, again: Module Loading Problem

 
 
fowlertrainer@anonym.hu
Guest
Posts: n/a
 
      01-05-2004
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






--
Best regards,
fowlertrainer (E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Module loading problem Mikail Dellovich C Programming 3 03-23-2007 11:40 PM
Re: module docstring, documentation,anything? please note is the module type/object NOT some module Maric Michaud Python 0 06-24-2006 12:42 PM
Problem Dynamic Loading Linux C++ .so module using python2.4 liam_herron Python 1 04-10-2006 07:52 PM
Loading module in another module Vito Corleone Perl Misc 3 01-10-2005 01:15 PM
Problem Dynamically Loading a Module Travis Whitton Ruby 2 09-15-2003 06:50 PM



Advertisments