Python 2.7.3 on Solaris 10
Questions
- When my subprocess has an internal separation problem (core), or a user externally kills it from the shell using SIGTERM or SIGKILL, my main program signal handler processes SIGTERM (-15), and my parent program terminates. It's real? or is it a poor python build?
Background and code
I have a python script that first spawns a worker control flow. Then, the control workflow spawns one or more workflows. I have other things that happen in my main thread that I cannot block. My management and workflows are robust. My services have been working for years without restarting, but then we have this subprocess.Popen script:
In the run method of a workflow, I use:
class workerThread(threading.Thread): def __init__(self) : super(workerThread, self).__init__() ... def run(self) ... atempfile = tempfile.NamedTempFile(delete=False) myprocess = subprocess.Popen( ['third-party-cmd', 'with', 'arguments'], shell=False, stdin=subprocess.PIPE, stdout=atempfile, stderr=subprocess.STDOUT,close_fds=True) ...
I need to use myprocess.poll() to check the completion of the process, because I need to scan atempfile until I find the relevant information (the file may be> 1 GiB), and I need to terminate the process due to a user request or because the process is running too long. As soon as I find what I'm looking for, I will stop checking the temp stdout file. I will clean it after the external process is dead, and before the workflow completes. I need stdin PIPE in case I need to insert a response to something interactive in the stdin stream for a child.
In my main program, I installed a SIGINT and SIGTERM handler to perform a cleanup if my main python program exits with SIGTERM or SIGINT (Ctrl-C) if executed from the shell.
Does anyone have a solid 2.x recipe for handling child signals in streams? ctypes sigprocmask etc.
Any help would be greatly appreciated. I'm just looking for an โofficialโ recipe or a BEST hack , if it even exists.
Notes
I am using a limited build of Python. I have to use 2.7.3. Third-party-cmd is a program for which I have no source - modification is not possible.