473,480 Members | 2,347 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
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?
Jul 12 '08 #1
4 3942
On 12 Jul., 11:30, John Dann <n...@prodata.co.ukwrote:
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
Jul 12 '08 #2
On Sat, 12 Jul 2008 10:30:00 +0100, John Dann wrote:
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.
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
Jul 12 '08 #3
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?

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
Jul 12 '08 #4
There is a module called sched in the standard Python library

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

/Jean Brouwers

John Dann 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?
Jul 13 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
5790
by: Eric | last post by:
I'm trying to have some scripts run periodically on Windows XP and found the "Task Scheduler" did not execute my scripts. My scripts are of the form scriptName.py, and will run just by invoking that...
3
3234
by: chrisdevey | last post by:
Is there any way to make a System.Timers.Timer adjust for daylight savings time change? In a long running process I set a timer as follows for a daily expiration: _myTimer = new...
8
1994
by: sm | last post by:
Hi All, I need to do a task at 3pm everyday. How do I set up the timer so that the timer procedure executes at 3pm everyday? Is there any other solution other than using a timer? Thanks.
5
1129
by: Mark | last post by:
Hello, Does anyone know of a timer control which has similar functionality as the scheduler in SQL server? I'm most interested in being able to set up recurring tasks. I want to stay away...
2
1771
by: Rohan | last post by:
Hello, I would like my script to run once a week with out any external interference. More like a timer. Can it be done in python or should some other shell scripting be used. If anyone knows...
3
2711
by: elaine | last post by:
I have a web appliacation, what i want to do is starting a timer when "Application_Start" event handler is called. The timer is running asyncronizely, let's say, every 24 hours, it will create a...
1
1794
by: Prof. William Battersea | last post by:
I'd like a class method to fire every n seconds. I tried this: class Timed: def.__init__(self): self.t = Timer(3, self.dothing) def.start(self): self.t.start()
0
860
by: Rob Weir | last post by:
On 14 Aug 2008, William Battersea wrote: That's how both ('sched' and threading.Timer) of the them work. Depending on what you're doing, your toolkit/framework (Twisted, GTK, etc) might have a...
0
1129
by: =?GB2312?B?zPC5zw==?= | last post by:
Howdy, I use python2.5 in WindowsXP. If using time.time() as timer, it seems the maximum precision is about 10-12ms. Maybe this is caused by the time slice defined in process scheduler. However,...
0
7051
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.