~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/internet/test/process_helper.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# A program which exits after starting a child which inherits its
 
3
# stdin/stdout/stderr and keeps them open until stdin is closed.
 
4
 
 
5
import sys, os
 
6
 
 
7
def grandchild():
 
8
    sys.stdout.write('grandchild started')
 
9
    sys.stdout.flush()
 
10
    sys.stdin.read()
 
11
 
 
12
def main():
 
13
    if sys.argv[1] == 'child':
 
14
        if sys.argv[2] == 'windows':
 
15
            import win32api as api, win32process as proc
 
16
            info = proc.STARTUPINFO()
 
17
            info.hStdInput = api.GetStdHandle(api.STD_INPUT_HANDLE)
 
18
            info.hStdOutput = api.GetStdHandle(api.STD_OUTPUT_HANDLE)
 
19
            info.hStdError = api.GetStdHandle(api.STD_ERROR_HANDLE)
 
20
            python = sys.executable
 
21
            scriptDir = os.path.dirname(__file__)
 
22
            scriptName = os.path.basename(__file__)
 
23
            proc.CreateProcess(
 
24
                None, " ".join((python, scriptName, "grandchild")), None,
 
25
                None, 1, 0, os.environ, scriptDir, info)
 
26
        else:
 
27
            if os.fork() == 0:
 
28
                grandchild()
 
29
    else:
 
30
        grandchild()
 
31
 
 
32
if __name__ == '__main__':
 
33
    main()