Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing? 31 26653
> > > Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run this bit of code" sort of thing?
why not just use the time.sleep() function ?
[Derek Fountain] Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run this bit of code" sort of thing?
Like this?
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
import threading
def hello():
print "hello, world"
t = threading.Timer (30.0, hello)
t.start() # after 30 seconds, "hello, world" will be printed
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Timers start a new thread of execution.
More info from here http://www.python.org/doc/current/li...r-objects.html
HTH,
--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Dave Harrison wrote: > > Does Python have a timer mechanism? i.e. an "after 500 milliseconds, > > run this bit of code" sort of thing?
why not just use the time.sleep() function ?
Because that stops the thread. I want things to continue, and then be
interrupted in order to execute a bit of code. Tcl has the 'after' command:
after 5000 { set disabled 0 }
The script carries on, and after 5 seconds whatever is being done gets
interrupted in order to run a bit of script - in this case set a variable
turning off a disablement of some sort. This makes it trivial to implement
"disable this feature for 5 seconds" kinds of logic.
I can't find anything like that in Python.
Alan Kennedy wrote: [Derek Fountain] Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run this bit of code" sort of thing?
Like this? http://www.python.org/doc/current/li...r-objects.html
That looks like what I'm after, yes. I haven't looked into threads since
they've represented trouble in every other language I've used. But I'll
have a look into their implementation in Python and see if they're any more
usable here...
Thanks.
At 9:04 PM +0800 27/10/03, Derek Fountain wrote: Dave Harrison wrote:
> > Does Python have a timer mechanism? i.e. an "after 500 milliseconds, > > run this bit of code" sort of thing?
why not just use the time.sleep() function ?
Because that stops the thread. I want things to continue, and then be interrupted in order to execute a bit of code. Tcl has the 'after' command:
after 5000 { set disabled 0 }
The script carries on, and after 5 seconds whatever is being done gets interrupted in order to run a bit of script - in this case set a variable turning off a disablement of some sort.
Wow, that must make your scripts so much more interesting to debug ;)
Anthony
--
----------------------------------------------------
HyPEraCtiVE? HeY, WhO aRE YoU cALliNg HypERaCtIve?! aB*****@wEStNeT .cOm.aU
----------------------------------------------------
At 09:21 PM 10/26/2003, Derek Fountain wrote: Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run this bit of code" sort of thing?
Check out the sched and time modules.
Bob Gailer bg*****@alum.rp i.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system ( http://www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 10/9/2003
In article <3f************ ***********@fre enews.iinet.net .au>,
Derek Fountain <no****@hursley .ibm.com> wrote: Dave Harrison wrote:
> > Does Python have a timer mechanism? i.e. an "after 500 milliseconds, > > run this bit of code" sort of thing?
why not just use the time.sleep() function ?
Because that stops the thread.
Check out the threading module. In particular, the threading.Timer class. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: HL |
last post by:
I am using VS 2005 Beta - C#
Problem: The Timer fires a few milliseconds before the actual Due-Time
Let's say a timer is created in the following manner:
System.Threading.Timer m_timer = null;
Let's declare a constant
Int32 m_TimePeriod = 10000;
|
by: John David Thornton |
last post by:
I've got a Windows Service class, and I put a System.Threading.Timer, and
I've coded it as shown below. However, when I install the service and then
start it in MMC, I get a peculiar message:
The MyService service on Local Computer started and then stopped. Some
services stop automatically if they ahve no work to do, for example, the
Perforamnce Logs and Alert service.
I tried switching to a System.Threading.Timer and that didn't work...
|
by: Gina_Marano |
last post by:
I have created an array of timers (1-n). At first I just created
windows form timers but I read that system timers are better for
background work. The timers will just be monitoring different
directories and updating a database. No interaction with the GUI.
Problem is that the system timers do not have a tag property so I can
tie in an object.
example (old way):
|
by: KnighT |
last post by:
I have a .net service that runs a System.Threading.Timer. The delegate
points to the function that the service should execute when the timer
elapses. Problem: The timer is not ticking.
I have never used this timer. I used the documentation from Microsoft
as a guide, but I cannot get this timer to work.
Protected Overrides Sub OnStart(ByVal args() As String)
Dim myTimer As New TimerState()
|
by: =?Utf-8?B?RGF2ZSBCb29rZXI=?= |
last post by:
I have a Timer that I set to go off once a day, but it frequently fails! In
order to debug I would like to be able to check, at any moment, whether the
Timer is enabled and when it will next Elapse.
Is there any way -- whether in my code, or in the O/S -- to determine when a
Timer is scheduled to Elapse?
| |
by: Hotrod2000 |
last post by:
I'm quite new to programming but I'm having problems getting a timer
to work in visual studio.net
I've created a timer on a form, enabled it and then typed the
following code (from the mdsn library as I thought this would be a
good start!!!) but nothing happens :-
Imports System.Timers
|
by: Peter Oliphant |
last post by:
Note that although this involves SAPI, it is more a question about Timers
and event handlers.
I wrote a Speech Recognize handler (SAPI), and put some code in it to enable
a Timer. It would not do it. If I bring this same code outside this event
handler, it works just fine.
Is this normal?
|
by: Anil Gupte/iCinema.com |
last post by:
When I use this
Dim instance As New Timer
I get the error: Error 1 Overload resolution failed because no accessible
'New' accepts this number of arguments.
Yet, in the help section for Timer (in VB 2005) this is exactly the syntax
shown. I also tried:
|
by: Steve |
last post by:
Hi All
I am using VB.net 2008 and use timer controls within my applications
Question
Does the code in a Timer control.tick event run on a different thread to the
main Application thread (UI Thread)?
In some of the timers I update some UI controls e.g statusbar.labels and I
|
by: Eran Hefer |
last post by:
With SharePoint timer jobs you can create & execute processes on a daily / hourly / minutely basis.
After deployment, the timer job definition executes your custom code.
The easiest (and more common) way to deploy a timer job is by feature.
When the feature is being activated, a custom code on the "FeatureActivated" method should install the timer job.
This is a complete example of how to create and deploy a timer job definition.
...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |