[code.view]

[top] / python / PyMOTW / subprocess / subprocess_signal_parent_shell.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2009 Doug Hellmann All rights reserved.
     #
     """
     """
     #end_pymotw_header
     
     import os
     import signal
     import subprocess
     import tempfile
     import time
     import sys
     
     script = '''#!/bin/sh
     echo "Shell script in process $$"
     set -x
     python signal_child.py
     '''
     script_file = tempfile.NamedTemporaryFile('wt')
     script_file.write(script)
     script_file.flush()
     
     proc = subprocess.Popen(['sh', script_file.name], close_fds=True)
     print 'PARENT      : Pausing before sending signal to child %s...' % proc.pid
     sys.stdout.flush()
     time.sleep(1)
     print 'PARENT      : Signaling child %s' % proc.pid
     sys.stdout.flush()
     os.kill(proc.pid, signal.SIGUSR1)
     time.sleep(3)
     

[top] / python / PyMOTW / subprocess / subprocess_signal_parent_shell.py

contact | logmethods.com