开发者

Terminal window close eventhandler in python for linux

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):
 开发者_如何学Python  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...


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. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜