Newbie question

Discussion in 'Python' started by Harry Knitter, Jul 23, 2004.

  1. Hello,

    I am new with Python and would like to know how to achieve to make a Python
    program continously listening if a certain data file is changed from
    another program.
    Thanks

    Harry

    p.s. Im working under Linux
    Harry Knitter, Jul 23, 2004
    #1
    1. Advertising

  2. Am Fri, 23 Jul 2004 13:03:47 +0200 schrieb Harry Knitter:

    > Hello,
    >
    > I am new with Python and would like to know how to achieve to make a Python
    > program continously listening if a certain data file is changed from
    > another program.
    > Thanks


    untested:

    import os
    import time

    file="...."
    mtime=os.path.getmtime(file)
    while 1:
    if os.path.getmtime(file)!=mtime:
    print "%s changed" % file
    mtime=os.path.getmtime(file)
    time.sleep(1)

    --
    Thomas G├╝ttler, http://www.thomas-guettler.de/
    Thomas Guettler, Jul 23, 2004
    #2
    1. Advertising

  3. Thomas Guettler wrote:

    > Am Fri, 23 Jul 2004 13:03:47 +0200 schrieb Harry Knitter:
    >
    >> Hello,
    >>
    >> I am new with Python and would like to know how to achieve to make a
    >> Python
    >> program continously listening if a certain data file is changed from
    >> another program.
    >> Thanks

    >
    > untested:
    >
    > import os
    > import time
    >
    > file="...."
    > mtime=os.path.getmtime(file)
    > while 1:
    > if os.path.getmtime(file)!=mtime:
    > print "%s changed" % file
    > mtime=os.path.getmtime(file)
    > time.sleep(1)
    >

    Thanks, however, how do I have to invoke this procedure avoiding the program
    remaining in this endles loop.What I want to achieve is, that the program
    does something, when the file is changed an then listening again. Meanwhile
    the user shoud be able to use the program as usual. i.e. I need this
    procedure as a background process triggering a special action.

    Harry
    Harry Knitter, Jul 23, 2004
    #3
  4. Harry Knitter <> wrote:
    > Thanks, however, how do I have to invoke this procedure avoiding the program
    > remaining in this endles loop.What I want to achieve is, that the program
    > does something, when the file is changed an then listening again. Meanwhile
    > the user shoud be able to use the program as usual. i.e. I need this
    > procedure as a background process triggering a special action.


    I don't have time at the moment to post example code, but you'll
    want to make a class of it, and make that class a thread
    (http://docs.python.org/lib/module-threading.html) so it can run in
    the background while your program does other things.

    --
    Kristofer Pettijohn
    Kristofer Pettijohn, Jul 23, 2004
    #4
    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. Jerry C.
    Replies:
    8
    Views:
    215
    Uri Guttman
    Nov 23, 2003
  2. Kruno Saho
    Replies:
    0
    Views:
    132
    Kruno Saho
    Apr 7, 2013
  3. Dave Angel
    Replies:
    0
    Views:
    114
    Dave Angel
    Apr 7, 2013
  4. rusi
    Replies:
    0
    Views:
    103
  5. Miki Tebeka
    Replies:
    0
    Views:
    76
    Miki Tebeka
    Apr 7, 2013
Loading...

Share This Page