[Tutor] (no subject)

Kent Johnson kent37 at tds.net
Wed Dec 1 12:01:41 CET 2004


I was looking through your other posts and saw the question about pickling and the one about 
detecting changed files. It makes me think, if you have control of both writing and reading of this 
data, you should consider a multi-user database. Then the database will take care of all the 
concurrency issues for you. If you are only appending to the database then checking for new items is 
just a matter of counting rows in the db. If you also change items you could store a time stamp in 
the db and check it periodically for changes. With a db you can retrieve sorted data or subsets easily.


Jeff Peery wrote:
> hello again,
> I am thoroughly confused. I am using Timer from the threading module. I 
> want to check a specific file every few minutes to see if it has been 
> altered (I do this by checking the size of the file using stat) if it 
> hasn't then I do nothing, if it has then I attempt to read the file, 
> grab all the new numerical data and update a graph on my computer.
> this file I am reading holds liquid volumetric flow rate measurement 
> data and the python code I am writing is to be used as a statistical 
> process control. basically I watch the results from the measurements by 
> watching a particular file for updates, when an update occurs I grab the 
> data do some more stats, then update my graphs that show on my desktop.
> the timer I used is a class, so I defined a new object (I think thats 
> the right word) as:
>     myTimer = Timer(30.0, Update)
> where the timer runs every 30 seconds and Update is a function that 
> checks if the file has been altered and if so then it updates my graphs. 
> I then start the timer:
>     myTimer.start()
> I am confused by two things:
> 1) I want my timer to restart every 30 seconds. as it shows above it 
> will go just one time. If I put this in a while loop, will the while 
> loop loop through the start command faster than 30 second intervals or 
> will it wait for the timer to execute the Update function before calling 
> timer.start() again?
> 2) I am also confused about how variables are handled when I have 
> multiple and nested functions. for example, I would like to initiate the 
> Update function every 30 seconds and I want the Update funtion to return 
> any new data. how can I return something from a function when the 
> function is called from a timer? I cannot do an assignment statement 
> from within the definnition of myTimer? or do I even need to return the 
> data? if I create a variable in the update function is it available in 
> my main function? I am not sure how python handles variables that are 
> defined in different functions.
> thank you very much for spending the time to help me, I appreciate it!
> Jeff
> ------------------------------------------------------------------------
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list