<s> """<STR_LIT>""" <EOL> import os <EOL> try : <EOL> from signal import set_wakeup_fd , siginterrupt <EOL> except ImportError : <EOL> set_wakeup_fd = siginterrupt = None <EOL> try : <EOL> import signal <EOL> except ImportError : <EOL> signal = None <EOL> from twisted . python . log import msg <EOL> try : <EOL> from twisted . internet . _sigchld import installHandler as _extInstallHandler , isDefaultHandler as _extIsDefaultHandler <EOL> except ImportError : <EOL> _extInstallHandler = _extIsDefaultHandler = None <EOL> class _Handler ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fd ) : <EOL> self . fd = fd <EOL> def __call__ ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if self . fd is not None : <EOL> try : <EOL> os . write ( self . fd , '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> def _installHandlerUsingSignal ( fd ) : <EOL> """<STR_LIT>""" <EOL> if fd == - <NUM_LIT:1> : <EOL> previous = signal . signal ( signal . SIGCHLD , signal . SIG_DFL ) <EOL> else : <EOL> previous = signal . signal ( signal . SIGCHLD , _Handler ( fd ) ) <EOL> if isinstance ( previous , _Handler ) : <EOL> return previous . fd <EOL> return - <NUM_LIT:1> <EOL> def _installHandlerUsingSetWakeup ( fd ) : <EOL> """<STR_LIT>""" <EOL> if fd == - <NUM_LIT:1> : <EOL> signal . signal ( signal . SIGCHLD , signal . SIG_DFL ) <EOL> else : <EOL> signal . signal ( signal . SIGCHLD , _Handler ( None ) ) <EOL> siginterrupt ( signal . SIGCHLD , False ) <EOL> return set_wakeup_fd ( fd ) <EOL> def _isDefaultHandler ( ) : <EOL> """<STR_LIT>""" <EOL> return signal . getsignal ( signal . SIGCHLD ) == signal . SIG_DFL <EOL> def _cannotInstallHandler ( fd ) : <EOL> """<STR_LIT>""" <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> def _cannotDetermineDefault ( ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> if set_wakeup_fd is not None : <EOL> msg ( '<STR_LIT>' ) <EOL> installHandler = _installHandlerUsingSetWakeup <EOL> isDefaultHandler = _isDefaultHandler <EOL> elif _extInstallHandler is not None : <EOL> msg ( '<STR_LIT>' ) <EOL> installHandler = _extInstallHandler <EOL> isDefaultHandler = _extIsDefaultHandler <EOL> elif signal is not None : <EOL> msg ( '<STR_LIT>' ) <EOL> installHandler = _installHandlerUsingSignal <EOL> isDefaultHandler = _isDefaultHandler <EOL> else : <EOL> msg ( '<STR_LIT>' ) <EOL> installHandler = _cannotInstallHandler <EOL> isDefaultHandler = _cannotDetermineDefault </s>
