reloading updated modules in long running server?

Discussion in 'Python' started by aurora, Oct 15, 2004.

  1. aurora

    aurora Guest

    I am looking for a way for reloading updated modules in a long running
    server. I'm not too concerned about cascaded reload or objects already
    created. Just need to reload module xxx if the corresponding xxx.py is
    updated.

    I found something useful in module.__file__. Would it work if I use it to
    generate filenames xxx.py xxx.pyc and then compare their mtime? I'm not
    too sure about the mechanism of generation of .pyc file. Would it be too
    system specific to reply on?
    aurora, Oct 15, 2004
    #1
    1. Advertising

  2. I don't know if there is a way to catch the event "a file has been
    modified in the file system" but you can always check if something has
    changed in sys.modules every time a request is processed by the server,
    or every n second

    Something like this should work :

    updateTime={}
    for m in sys.modules.values():
    if m and hasattr(m,"__file__"):
    modTime=os.path.getmtime(m.__file__)
    if updateTime.has_key(m):
    if modTime != updateTime[m]:
    reload(m)
    updateTime[m]=modTime
    else:
    updateTime[m]=modTime

    Pierre

    aurora a écrit :
    > I am looking for a way for reloading updated modules in a long running
    > server. I'm not too concerned about cascaded reload or objects already
    > created. Just need to reload module xxx if the corresponding xxx.py is
    > updated.
    >
    > I found something useful in module.__file__. Would it work if I use it
    > to generate filenames xxx.py xxx.pyc and then compare their mtime? I'm
    > not too sure about the mechanism of generation of .pyc file. Would it
    > be too system specific to reply on?
    Pierre Quentel, Oct 16, 2004
    #2
    1. Advertising

  3. aurora

    Bryan Guest

    Pierre Quentel wrote:
    > I don't know if there is a way to catch the event "a file has been
    > modified in the file system" but you can always check if something has
    > changed in sys.modules every time a request is processed by the server,
    > or every n second
    >
    > Something like this should work :
    >
    > updateTime={}
    > for m in sys.modules.values():
    > if m and hasattr(m,"__file__"):
    > modTime=os.path.getmtime(m.__file__)
    > if updateTime.has_key(m):
    > if modTime != updateTime[m]:
    > reload(m)
    > updateTime[m]=modTime
    > else:
    > updateTime[m]=modTime
    >
    > Pierre
    >


    if you have class A in module a.py and class B(A) in module b.py, and in module c.py you instantiale b = B(). will
    there be a problem if you reload module b, then c, then a? in the previous example, m in sys.modules.values() doesn't
    take this into account.

    bryan
    Bryan, Oct 16, 2004
    #3
    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. Colin Ryan
    Replies:
    0
    Views:
    578
    Colin Ryan
    Feb 18, 2004
  2. George Marsaglia

    Assigning unsigned long to unsigned long long

    George Marsaglia, Jul 8, 2003, in forum: C Programming
    Replies:
    1
    Views:
    658
    Eric Sosman
    Jul 8, 2003
  3. Guest
    Replies:
    2
    Views:
    259
    Lee Harr
    Oct 15, 2004
  4. Peter Peyman Puk

    Importing v reloading modules modules

    Peter Peyman Puk, Mar 19, 2010, in forum: Python
    Replies:
    0
    Views:
    290
    Peter Peyman Puk
    Mar 19, 2010
  5. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    402
    Dmitry Korolyov
    Sep 22, 2003
Loading...

Share This Page