473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to create a loop based on time (a.k.a "Heartbeat")

3
I'm wondering how can I create a time-based loop that runs based on a certain interval i.e. something similar to:

while 1:
# do something
time.sleep(1)

but more elegant and "balanced", in the above example if "do something" takes 500ms then the actual loop'll run every 1.5 instead of 1 second, and if this "do something" varies, the loop itself's unstable too.

Any suggestions?
May 5 '10 #1
1 2742
Glenton
391 Expert 256MB
You could use the built in time functions.

Something like this:
Expand|Select|Wrap|Line Numbers
  1. while 1:
  2.     now=time.time()
  3.     print time.time()-now, "doing something"
  4.     time.sleep(max[0,1-(time.time()-now)])
May 10 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Annette Massie | last post by:
I have a bunch of images stored in a folder on the harddrive. Is there a way for Access 2000 to read the directory and write a record for the images found? Eventually the records need to be...
7
by: barney.b | last post by:
Hi, Is there a wrapper class, or combination of classes, that will allow me to do the following: class Wrapper extends java.io.OutputStream { public void...
2
by: thilandeneth | last post by:
i need to do telnet via a web server please give me a idia to initiate the project following requirements are needed 1 Create web based custom telnet client to communicate with remote...
4
by: ringer | last post by:
I have a db where each record is a certain task to be done. Each record includes the date the task should be completed. Some of the tasks are one time only but some are recurring. I have been having...
1
by: Emmanouil | last post by:
Goodmorning to every body!!!!! My "problem" for 2day is this: I have a column in a access database with 50 cells, let us say. All cells are filled with 1 and 0 quite like these: 1 0 0 1 1 0
0
by: db2admin | last post by:
Hi, I want to create web based directory of all the databases we have in our corporation ( @ 100 ) I want to have listing of databases categorized by project , business etc. If possible, I...
5
by: mukeshrasm | last post by:
Hi I want to create table based structure but without using table tag. I want to use div tag. How can I do that?
5
by: theine | last post by:
How do I create Hyperlink based of a specific field in the same row? In Excel it done like this: =HYPERLINK("", A273) where the anything inside the " " is the value it's looking for in that...
3
by: brendanmcdonagh | last post by:
I have these values in an array after using split $alltogether = $day . "," . $month . "," . $hour . "," . $minutes . ","; $arr=split(",",$alltogether); // splitting the array $d=$arr; //...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
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
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...

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.