Twisted program and TERM signal

I have a simple example:

    from twisted.internet import utils, reactor

    def test:
        utils.getProcessOutput (executable = "/ bin / sleep", args = ["10000"])

    reactor.callWhenRunning (test)
    reactor.run ()

when I send a “TERM” signal for programming, “sleep” continues to execute when I press Ctrl-C on the keyboard to “sleep” a stop. (Ctrl-C is not an equivalent TERM signal?) Why? How to kill "sleep" after sending the "TERM" signal to this program?

+5
source share
1 answer

Ctrl-C SIGINT . , Twisted- sleep.

, Python , :

def killSleep():
    # Do it, somehow

reactor.addSystemEventTrigger('before', 'shutdown', killSleep)

, killSleep . getProcessOutput , (, pid). reactor.spawnProcess ProcessProtocol, , - ProcessProtocol , signalProcess, SIGTERM ( ) .

SIGINT , :

import os, signal

def killGroup():
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    os.kill(-os.getpgid(os.getpid()), signal.SIGINT)

reactor.addSystemEventTrigger('before', 'shutdown', killGroup)

SIGINT, Twisted , (, , , , ). -os.getpgid(os.getpid()) , .

+4

All Articles