Connecting Tech Pros Worldwide Forums | Help | Site Map

How to create a timer/scheduler in Python?

John Dann
Guest
 
Posts: n/a
#1: Jul 12 '08
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?

Uwe Schmitt
Guest
 
Posts: n/a
#2: Jul 12 '08

re: How to create a timer/scheduler in Python?


On 12 Jul., 11:30, John Dann <n...@prodata.co.ukwrote:
Quote:
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
Marc 'BlackJack' Rintsch
Guest
 
Posts: n/a
#3: Jul 12 '08

re: How to create a timer/scheduler in Python?


On Sat, 12 Jul 2008 10:30:00 +0100, John Dann wrote:
Quote:
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.
Look into the GUI toolkit because that's typically something solved with
functions from the specific toolkit.
Quote:
Is there really no simple timer/scheduler function available in
Python?
You can do that quite easily with threads but almost all GUI toolkits
don't like it if you access the GUI from multiple threads.

Ciao,
Marc 'BlackJack' Rintsch
Daniel Fetchinson
Guest
 
Posts: n/a
#4: Jul 12 '08

re: How to create a timer/scheduler in Python?


I need what I'd call (in .Net) a timer, ie I need to run a function eg
Quote:
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?

You might want to look at scheduler.py from turbogears which is
exactly the tool you describe and luckily is 99.99% independent of
turbogears. I'd think you need to modify 1-2 lines:

http://svn.turbogears.org/tags/1.0.4...s/scheduler.py

Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
MrJean1
Guest
 
Posts: n/a
#5: Jul 13 '08

re: How to create a timer/scheduler in Python?


There is a module called sched in the standard Python library

<http://docs.python.org/lib/module-sched.html>

/Jean Brouwers



John Dann wrote:
Quote:
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?
Closed Thread


Similar Python bytes