Search code examples
subprocesstornado

Whats the right way to terminate/kill and get return code for a tornado.subprocess?


I able to launch a tornado subprocess

sp = tornado.process.subprocess(..)

but want to have the ability to kill the same on some event.

The only way I could manage to do this, by perusing the code, is to use the terminate() method of the 'proc' attribute of the tornado subprocess object since the tornado subprocess constructor initializes the 'proc' attribute to the Subprocess Popen. So :

sp.proc.terminate()

seems to work. However I am not sure that's the best way

Also how to get the returncode? Trying to use

sp.proc.returncode

seems to return None


Solution

  • Yes, sp.proc.terminate() is currently the best way; we don't expose either the terminate method or the process ID directly.

    To get the return code, you must use sp.wait_for_exit() or sp.set_exit_callback().