By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,563 Members | 1,280 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,563 IT Pros & Developers. It's quick & easy.

how to interrupt time.sleep ?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.