Interrupt Sleep function

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Interrupt Sleep function

 
0
  #1
Sep 13th, 2005
Is there a way one can interrupt the sleep() function with a key press in Python?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Interrupt Sleep function

 
0
  #2
Sep 13th, 2005
Look at KeyboardInterrupt in the Python reference. Right now, I don't have a good example. I try to work on one!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Interrupt Sleep function

 
0
  #3
Sep 14th, 2005
So far I have only found one function that will work during the active sleep() ...
  1. import time
  2. import msvcrt
  3. time.sleep(10)
  4. # prints the key value during sleep
  5. if msvcrt.kbhit():
  6. print msvcrt.getch()
Edit:
Ouch! The IDE fooled me! This does not make sense, forget it! Sorry!
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Interrupt Sleep function

 
0
  #4
Sep 15th, 2005
If it's anything like the sleep(t) function I have been using with C++, there is no way to stop it early. Maybe ctrl/alt/del, but that is not what you want to normally do.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 138
Reputation: a1eio is an unknown quantity at this point 
Solved Threads: 21
a1eio's Avatar
a1eio a1eio is offline Offline
Junior Poster

Re: Interrupt Sleep function

 
0
  #5
Sep 16th, 2005
havn't got an example, but my very rough guess is maybe you could do something along the lines of;

wrap a function around the time.sleep() function that when called it starts the sleep in another thread so that the program will only continue untill;
sleep ends,
thread gets killed (stoppped)
so the way to interrupt could be to manually shut down the thread which in turn would shut down the sleep

OR

you could make your own sleep class that allows you to kill it?

something along those lines anyway
not too experienced on threading or using classes
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,109
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 943
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Interrupt Sleep function

 
0
  #6
Sep 17th, 2005
Thanks a1eio,
I just remembered hanging an old Delphi snippet on the DaniWeb code snippet laundry line a long time ago, that talked about the very same thing that Ene brought up.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 138
Reputation: a1eio is an unknown quantity at this point 
Solved Threads: 21
a1eio's Avatar
a1eio a1eio is offline Offline
Junior Poster

Re: Interrupt Sleep function

 
0
  #7
Sep 19th, 2005
no probs, glad i could help

*edit: that smiley looks evil
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC