#NEWLINE# def __init__( self , reactor , executable , args , environment , path , proto , uid = None , gid = None , childFDs = None ) : #NEWLINE# #INDENT# "\n        Spawn an operating-system process.\n\n        This is where the hard work of disconnecting all currently open\n        files / forking / executing the new process happens.  (This is\n        executed automatically when a Process is instantiated.)\n\n        This will also run the subprocess as a given user ID and group ID, if\n        specified.  (Implementation Note: this doesn't support all the arcane\n        nuances of setXXuid on UNIX: it will assume that either your effective\n        or real UID is 0.)\n        " #NEWLINE# if ( not proto ) : #NEWLINE# #INDENT# assert ( 'r' not in childFDs . values ( ) ) #NEWLINE# assert ( 'w' not in childFDs . values ( ) ) #NEWLINE# #UNINDENT# _BaseProcess . __init__ ( self , proto ) #NEWLINE# self . pipes = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# helpers = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if ( childFDs is None ) : #NEWLINE# #INDENT# childFDs = { #NEWLINE# #INDENT# 0 : 'w' , #NEWLINE# 1 : 'r' , #NEWLINE# 2 : 'r' , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# debug = self . debug #NEWLINE# if debug : #NEWLINE# #INDENT# print ( 'childFDs' , childFDs ) #NEWLINE# #UNINDENT# _openedPipes = [ ] #NEWLINE# def pipe( ) : #NEWLINE# #INDENT# ( r , w ) = os . pipe ( ) #NEWLINE# _openedPipes . extend ( [ r , w ] ) #NEWLINE# return ( r , w ) #NEWLINE# #UNINDENT# fdmap = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# for ( childFD , target ) in items ( childFDs ) : #NEWLINE# #INDENT# if debug : #NEWLINE# #INDENT# print ( ( '[%d]' % childFD ) , target ) #NEWLINE# #UNINDENT# if ( target == 'r' ) : #NEWLINE# #INDENT# ( readFD , writeFD ) = pipe ( ) #NEWLINE# if debug : #NEWLINE# #INDENT# print ( ( 'readFD=%d, writeFD=%d' % ( readFD , writeFD ) ) ) #NEWLINE# #UNINDENT# fdmap [ childFD ] = writeFD #NEWLINE# helpers [ childFD ] = readFD #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( target == 'w' ) : #NEWLINE# #INDENT# ( readFD , writeFD ) = pipe ( ) #NEWLINE# if debug : #NEWLINE# #INDENT# print ( ( 'readFD=%d, writeFD=%d' % ( readFD , writeFD ) ) ) #NEWLINE# #UNINDENT# fdmap [ childFD ] = readFD #NEWLINE# helpers [ childFD ] = writeFD #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( type ( target ) == int ) , ( '%r should be an int' % ( target , ) ) #NEWLINE# fdmap [ childFD ] = target #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if debug : #NEWLINE# #INDENT# print ( 'fdmap' , fdmap ) #NEWLINE# #UNINDENT# if debug : #NEWLINE# #INDENT# print ( 'helpers' , helpers ) #NEWLINE# #UNINDENT# self . _fork ( path , uid , gid , executable , args , environment , fdmap = fdmap ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# for pipe in _openedPipes : #NEWLINE# #INDENT# os . close ( pipe ) #NEWLINE# #UNINDENT# raise #NEWLINE# #UNINDENT# self . proto = proto #NEWLINE# for ( childFD , parentFD ) in items ( helpers ) : #NEWLINE# #INDENT# os . close ( fdmap [ childFD ] ) #NEWLINE# if ( childFDs [ childFD ] == 'r' ) : #NEWLINE# #INDENT# reader = self . processReaderFactory ( reactor , self , childFD , parentFD ) #NEWLINE# self . pipes [ childFD ] = reader #NEWLINE# #UNINDENT# if ( childFDs [ childFD ] == 'w' ) : #NEWLINE# #INDENT# writer = self . processWriterFactory ( reactor , self , childFD , parentFD , forceReadHack = True ) #NEWLINE# self . pipes [ childFD ] = writer #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# if ( self . proto is not None ) : #NEWLINE# #INDENT# self . proto . makeConnection ( self ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# log . err ( ) #NEWLINE# #UNINDENT# registerReapProcessHandler ( self . pid , self )