holsety
holsety

Reputation: 323

kill subprocess spawned by spawnProcess in twisted doesn't work

all

I start a process using spawnProcess and want to kill when my certain Factory stops.

something I wrote like these


p = SomeProtocol(ProcessProtocol)

reactor.spawnProcess(p, 'twistd', ['twistd', '-y', 'anotherMain.py'], {})

class Factory(ServerFactory):
...

    def StopFactory(self):
        # which is the p above
        p.transport.signalProcess("KILL")

I thought the subprocess will be killed which is not.

I tried using p.transport.signalProcess("KILL") some other place, and it works.

What's wrong with my code? Thanks!

Upvotes: 0

Views: 853

Answers (1)

Maxim
Maxim

Reputation: 1803

This can be because twistd daemonizes anotherMain.py. After anotherMain.py becomes a daemon twistd process exits. So anotherMain.py isn't really a subprocess of your main process.

Try to add -n option:

reactor.spawnProcess(p, 'twistd', ['twistd', '-ny', 'anotherMain.py'], {})

Upvotes: 1

Related Questions