Sorry, again: Module Loading Problem

Discussion in 'Python' started by fowlertrainer@anonym.hu, Jan 5, 2004.

  1. Guest

    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 mailto:
     
    , Jan 5, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper

    Sorry for posting again

    Showjumper, Jan 26, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    357
    =?Utf-8?B?QWxleCBDLiBCYXJiZXJp?=
    Jan 27, 2006
  2. amit
    Replies:
    0
    Views:
    394
  3. che
    Replies:
    2
    Views:
    502
  4. abcd

    Importing again and again

    abcd, Jun 8, 2006, in forum: Python
    Replies:
    9
    Views:
    330
    Maric Michaud
    Jun 9, 2006
  5. Ò»Ê×Ê«

    A design problem I met again and again.

    Ò»Ê×Ê«, Apr 1, 2009, in forum: Python
    Replies:
    24
    Views:
    728
    Dennis Lee Bieber
    Apr 4, 2009
Loading...

Share This Page