(You put your response in the wrong place; it belongs after the part
you're quoting.)
he
On 11/29/2011 10:19 AM, bod...@googlemail.com wrote:
You won't get it exactly on because the time it takes to call the function will
affect your trigger time.
I would use something like an infinite loop with a 1 second sleep after the
function call
Bodsda
Sent from my BlackBerry® wireless device
-----Original Message-----
From: "Mic"<o0m...@hotmail.se>
Sender: tutor-bounces+bodsda=googlemail....@python.org
Date: Tue, 29 Nov 2011 15:54:59
To:<tutor@python.org>
Subject: [Tutor] Making a function run every second.
Hi
I want a function to run every second , how do I do that?
Say that the function look like this:
def hi():
print("hi")
Thanks!
Mic
Without a clearer spec, there are too many possible answers. As Bobsda
says, you can't get it exactly one second apart. But you also have the
problem of whether a drift is okay. For example, if you have a global
you're incrementing each time that function runs, and you want it to
represent the total time the program has been running, then a simple
sleep() is totally wrong.
What I was concerned about is that perhaps this is for one of the
tkinter programs Mic is writing. For an event-driven program, sleep()
calls of even a second are unaccepable. And if you literally write a
while loop like that, your whole program would stop responding.
So Mik:
Tell us more about the real requirements. Is drift acceptable, is this
a console program or some gui environment, are there any other hidden
assumptions?
--
DaveA
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor