Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newbie question

Reply
Thread Tools

Newbie question

 
 
Harry Knitter
Guest
Posts: n/a
 
      07-23-2004
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
 
Reply With Quote
 
 
 
 
Thomas Guettler
Guest
Posts: n/a
 
      07-23-2004
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/


 
Reply With Quote
 
 
 
 
Harry Knitter
Guest
Posts: n/a
 
      07-23-2004
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
 
Reply With Quote
 
Kristofer Pettijohn
Guest
Posts: n/a
 
      07-23-2004
Harry Knitter <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments