473,473 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to interrupt time.sleep ?

I have line "time.sleep(60)" in my code

How do I cancel waiting 60 seconds if I want to continue with program
imediately ? Like "Press some button if you don't want to wait"

If it can't be canceled what's the other solution to
"wait certain time/or press any button to continue" problem ?
Jul 18 '05 #1
3 13651
On Tue, 22 Feb 2005 22:37:28 +0100,
BOOGIEMAN <BO*********@YAHOO.COM> wrote:
I have line "time.sleep(60)" in my code
How do I cancel waiting 60 seconds if I want to continue with program
imediately ? Like "Press some button if you don't want to wait" If it can't be canceled what's the other solution to
"wait certain time/or press any button to continue" problem ?


Use the select module.

HTH,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
μ₀ × ε₀ × c² = 1
Jul 18 '05 #2
BOOGIEMAN wrote:
I have line "time.sleep(60)" in my code

How do I cancel waiting 60 seconds if I want to continue with program
imediately? Like "Press some button if you don't want to wait"
You cannot.
If it can't be canceled what's the other solution to
"wait certain time/or press any button to continue" problem ?


Generally you can just use a much shorter sleep time, and a loop
that checks for the condition which interests you.

while True:
if userWantsToContinue():
break
time.sleep(0.25) # wait a short time
The implementation of userWantsToContinue() depends of course on
what you want it to do. If you need help with that, be sure to
indicate what platform you're on so the answers can be meaningful
if the solution (as is likely in this case) is not platform-
independent.

-Peter
Jul 18 '05 #3
BOOGIEMAN <BO*********@YAHOO.COM> writes:
I have line "time.sleep(60)" in my code

How do I cancel waiting 60 seconds if I want to continue with program
imediately ? Like "Press some button if you don't want to wait"

If it can't be canceled what's the other solution to
"wait certain time/or press any button to continue" problem ?


On windows at least, pressing ^C interrupts time.sleep().

print "Press ^C if you don't want to wait"
try:
time.sleep(60)
except KeyboardInterrupt:
pass

Thomas

Jul 18 '05 #4

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

Similar topics

19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
7
by: Colin Brown | last post by:
Python 2.3.3 Under Windows NT: Negative Int or Real -> sleeps for a long time Under Linux: Returns IOError: Invalid argument I consider both of these unfriendly results and expected the...
3
by: Russell Stuart via .NET 247 | last post by:
I always though .Net monitors were meant to be similar to thejava synchronisation mechanisms. The code below proves mewrong. When run under the debugger, it produces just "Thread 1"lines, as I...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
27
by: tomhr | last post by:
I have a Borland Turbo C++ compiler (though I never use the "plus-plus" part), copyright 1990. I use this compiler to write simple programs, one of which I am quite dependent on. A month ago, my...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
1
by: =?Utf-8?B?TXJOb2JvZHk=?= | last post by:
I have a problem where I am sending a series of commands using P/Invoke's SendInput function which may last up to a minute long. I want to offer the user a way to break the commands by pressing the...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
1
by: yrs7 | last post by:
Could anyone tell me what I need to do to wakeup/interrupt a sleep() function in C? Thanks!
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...
1
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
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...
0
agi2029
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,...
1
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
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
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.