2

My Python program is running in ubuntu terminal window.If the terminal window is directly closed, need an event to occur and in that event i will send a message to server that application is exited. I tried with the following and it doesn't work.

def window_handler(self):
   CommandExecutor.processCommands(0, ProjectConstants.EXIT)             

signal.signal(signal.SIGTERM, window_handler) 

I have tried other signals too... How could i achieve this? Thanks in advance...

1 Answer 1

1

Closing a terminal will send SIGHUP to the processes which have that terminal's pseudo-tty as their controlling terminal.

Thus catching SIGHUP instead of SIGTERM should work.

I am unsure if there are some special considerations that you need to take in account when handling signals in Python, but that is a topic for another question. :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.