Python - Trap all signals

前端 未结 8 1462
慢半拍i
慢半拍i 2020-11-30 04:54

In python 2.6 under Linux, I can use the following to handle a TERM signal:

import signal
def handleSigTERM():
    shutdown()
signal.signal(signal.SIGTERM, h         


        
8条回答
  •  暖寄归人
    2020-11-30 05:14

    For Python 3:

    for sig in signal.Signals:
        try:
            signal.signal(sig, sighandler)
        except OSError:
            print('Skipping', sig)
    

提交回复
热议问题