@contextmanager
def blockdetection(timeout):
 if (not timeout):
  (yield)
 else:
  old_handler = signals[u'ALRM']
  old_handler = (None if (old_handler == _on_blocking) else old_handler)
  signals[u'ALRM'] = _on_blocking
  try:
   (yield signals.arm_alarm(timeout))
  finally:
   if old_handler:
    signals[u'ALRM'] = old_handler
   signals.reset_alarm()

@ contextmanager def blockdetection ( timeout ) : if ( not timeout ) : ( yield ) else : old_handler = signals [ u'ALRM' ] old_handler = ( None if ( old_handler == _on_blocking ) else old_handler ) signals [ u'ALRM' ] = _on_blocking try : ( yield signals . arm_alarm ( timeout ) ) finally : if old_handler : signals [ u'ALRM' ] = old_handler signals . reset_alarm ( )
context that raises an exception if process is blocking .