How to create a timer/scheduler in Python?

Uwe Schmitt rocksportrocker at googlemail.com
Sat Jul 12 12:39:12 CEST 2008


On 12 Jul., 11:30, John Dann <n... at prodata.co.uk> wrote:
> I need what I'd call (in .Net) a timer, ie I need to run a function eg
> every 2 seconds - it doesn't need to be millisec accurate but it would
> be nice if it wasn't eg every 4 seconds or something.
>
> Rather surprisingly, Core Python (Chun) doesn't seem to index 'timer'
> or 'scheduler', which leaves me wondering whether this is an aspect of
> Python that isn't perhaps widely used?
>
> Looking around on the net I can see references to a thread timer, but
> I'm not really looking to start any new threads (I just want part of
> the GUI to update every 2 secs) and don't want to get into that sort
> of complication while still just learning Python.
>
> Is there really no simple timer/scheduler function available in
> Python?

The usual way is to use threads. Depending on you GUI lib there may
exist
replacements for threads, eg wxPython. As most (all ?) GUIs have some
event handling
mechanisms they should be able to schedule tasks and process them in
the
background.

By the way: Using threads in Python is quite simple, even if you are
a  novice.

Greetings, Uwe



More information about the Python-list mailing list