Newbie question

H

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

Harry

p.s. Im working under Linux
 
T

Thomas Guettler

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)
 
H

Harry Knitter

Thomas said:
Am Fri, 23 Jul 2004 13:03:47 +0200 schrieb Harry Knitter:


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
 
K

Kristofer Pettijohn

Harry Knitter said:
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.
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top