Newbie question

Golawala, Moiz M (GE Infrastructure) Moiz.Golawala at
Fri Jul 23 15:25:55 CEST 2004

Hi Harry,

Try this piece of code:

from threading import Thread

class fooThread(Thread):
	def __init__(self):
		self.stopFlag = True
	def run(self):
		while self.stopFlag:
			if os.path.getmtime(file)!=mtime:
		      	print "%s changed" % file

	def stop(self):
		self.stopFlag = False

This is what you will write in you main class. You will start up the Thread and control it here.

class myMainClass:
	def __init__(self): = fooThread()
	def startThread(self):
			This is how you start the thread

	def stopThread(self):
			This is how you stop the thread

for more information on threads read this. (


-----Original Message-----
From: at
[ at]On Behalf Of
Harry Knitter
Sent: Friday, July 23, 2004 7:41 AM
To: python-list at
Subject: Re: Newbie question

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.


More information about the Python-list mailing list