code: def timeout(delay, handler=None):
      
      delay = int(delay)
      if handler is None:
          def default_handler(signum, frame):
              raise RuntimeError("{:d} seconds timeout expired".format(delay))
          handler = default_handler
      prev_sigalrm_handler = signal.getsignal(signal.SIGALRM)
      signal.signal(signal.SIGALRM, handler)
      signal.alarm(delay)
      yield
      signal.alarm(0)
      signal.signal(signal.SIGALRM, prev_sigalrm_handler)
docs: Context manager to run code and deliver a SIGALRM signal after `delay` seconds.
  
      Note that `delay` must be a whole number; otherwise it is converted to an
      integer by Python's `int()` built-in function. For floating-point numbers,
      that means rounding off to the nearest integer from below.
  
      If the optional argument `handler` is supplied, it must be a callable that
      is invoked if the alarm triggers while the code is still running. If no
      `handler` is provided (default), then a `RuntimeError` with message
      ``Timeout`` is raised.