Python Forum
Determine if keyboard interrupt versus SIGINT trapped?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determine if keyboard interrupt versus SIGINT trapped?
#1
Determine if keyboard interrupt versus SIGINT trapped?

Not sure there is a way to determine this per se? Looked via Google for method, but the best I could find or rather think of was:

Trap SIGINT and KeyboardInterrupt via signal handler, and test if session is interactive, say via sys.__stdin__.isatty(). But this would not be completely accurate, because if SIGINT is sent to python (session, i.e. executing script) from somewhere else, it still might have been an interactive session versus called via cron or as service emulation under systemd. Adding a test to see if systemd active maybe? Such as if psutil.Process(os.getpid()).ppid() == 1? But that is still not 100% bullet proof, right?
Reply


Messages In This Thread
Determine if keyboard interrupt versus SIGINT trapped? - by Jibunnokage - Sep-27-2022, 07:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  add interrupt for next task kucingkembar 0 800 Oct-07-2022, 12:15 PM
Last Post: kucingkembar
  Enabling interrupt on Adafruits button/led board Moris526 0 2,046 Apr-30-2021, 03:29 PM
Last Post: Moris526
  python delay without interrupt the whole code Nick_tkinter 4 5,259 Feb-22-2021, 10:51 PM
Last Post: nilamo
  Adafruits Neotrellis interrupt with RAsp and Python Moris526 5 3,664 Jan-01-2021, 11:43 PM
Last Post: Moris526
  Interrupt for Adafruits Neotrellis button/led board Moris526 0 1,837 Dec-28-2020, 05:42 AM
Last Post: Moris526
  input interrupt Nickd12 1 4,344 Dec-09-2020, 05:01 PM
Last Post: Gribouillis
  Wsgiref versus Requisitions JohnnyCoffee 1 1,669 Jun-14-2020, 05:15 PM
Last Post: Larz60+
  Config file entry as list versus string? taziuk 2 1,886 Apr-25-2020, 12:01 PM
Last Post: ndc85430
  How to determine pen color from an image? robie972003 2 2,470 Mar-24-2019, 10:06 PM
Last Post: robie972003
  determine if an number is in a list Dbeah 7 3,858 Nov-06-2018, 12:11 PM
Last Post: buran

Forum Jump:

User Panel Messages

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