Python Forum
Having difficulty with threads and input()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having difficulty with threads and input()
#9
How about using ctrl+c? If you are running from a console, ctrl+c raises a KeyboardInterrupt that your program can catch using try/except. Works for windows, osx, linux.
from time import sleep

print("Nighty night")
try:
    sleep(10)  # Standin for whatever work your script does
except KeyboardInterrupt:
    pass
print("Time to wake up")  # Standin for the cleanup.
Reply


Messages In This Thread
RE: Having difficulty with threads and input() - by deanhystad - Jun-05-2024, 12:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Difficulty in adapting duplicates-filter in script ledgreve 5 1,087 Jul-17-2023, 03:46 PM
Last Post: ledgreve
  Difficulty with installation standenman 2 1,170 May-03-2023, 06:39 PM
Last Post: snippsat
  Difficulty with installation standenman 0 795 May-02-2023, 08:33 PM
Last Post: standenman
  Difficulty in understanding transpose with a tuple of axis numbers in 3-D new_to_python 0 1,625 Feb-11-2020, 06:03 AM
Last Post: new_to_python
  Difficulty installing Pycrypto KipCarter 4 13,282 Feb-10-2020, 07:54 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020