[Tutor] (no subject)

orbitz orbitz at ezabel.com
Wed Dec 1 14:38:09 CET 2004

If you are on *NIX, there are python bindings for using libfam, which is 
a bit better than your current solution, but why not have a fifo or 
something so you just check if there is new data to be read after 
whatever it is that writes it, writes it, that way you don't have to do 
this constant checking.  Don't know what you mean by nested functions 
and all but:

def blah():
    def ooch():
       # ooch has access to all of the variables in blah's scope.

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

More information about the Tutor mailing list