code: def exit_after(s):
      
  
      def outer(fn):
          def inner(*args, **kwargs):
              timer = threading.Timer(s, thread.interrupt_main)
              timer.start()
              try:
                  result = fn(*args, **kwargs)
              except KeyboardInterrupt:
                  raise TimeoutError("Function '{}' hit the timeout ({}s).".format(fn.__name__, s))
              finally:
                  timer.cancel()
              return result
  
          return inner
  
      return outer
docs: Use as decorator to exit process if
      function takes longer than s seconds.
  
      Direct call is available via exit_after(TIMEOUT_IN_S)(fce)(args).
  
      Inspired by https://stackoverflow.com/a/31667005