parameters: (
      handler: Callable[[], None]
  )
docstring: Attach the given callback as a WINCH signal handler within the context
      manager. Restore the original signal handler when done.
  
      The `Application.run` method will register SIGWINCH, so that it will
      properly repaint when the terminal window resizes. However, using
      `run_in_terminal`, we can temporarily send an application to the
      background, and run an other app in between, which will then overwrite the
      SIGWINCH. This is why it's important to restore the handler when the app
      terminates.
docstring_summary: Attach the given callback as a WINCH signal handler within the context
      manager. Restore the original signal handler when done.
docstring_tokens: Attach the given callback as a WINCH signal handler within the context manager . Restore the original signal handler when done .
function: def attach_winch_signal_handler(
      handler: Callable[[], None]
  ) -> Generator[None, None, None]:
      """
      Attach the given callback as a WINCH signal handler within the context
      manager. Restore the original signal handler when done.
  
      The `Application.run` method will register SIGWINCH, so that it will
      properly repaint when the terminal window resizes. However, using
      `run_in_terminal`, we can temporarily send an application to the
      background, and run an other app in between, which will then overwrite the
      SIGWINCH. This is why it's important to restore the handler when the app
      terminates.
      """
      # The tricky part here is that signals are registered in the Unix event
      # loop with a wakeup fd, but another application could have registered
      # signals using signal.signal directly. For now, the implementation is
      # hard-coded for the `asyncio.unix_events._UnixSelectorEventLoop`.
  
      # No WINCH? Then don't do anything.
      sigwinch = getattr(signal, "SIGWINCH", None)
      if sigwinch is None or not in_main_thread():
          yield
          return
  
      # Keep track of the previous handler.
      # (Only UnixSelectorEventloop has `_signal_handlers`.)
      loop = get_event_loop()
      previous_winch_handler = getattr(loop, "_signal_handlers", {}).get(sigwinch)
  
      try:
          loop.add_signal_handler(sigwinch, handler)
          yield
      finally:
          # Restore the previous signal handler.
          loop.remove_signal_handler(sigwinch)
          if previous_winch_handler is not None:
              loop.add_signal_handler(
                  sigwinch,
                  previous_winch_handler._callback,
                  *previous_winch_handler._args,
              )
function_tokens: def attach_winch_signal_handler ( handler : Callable [ [ ] , None ] ) -> Generator [ None , None , None ] : # The tricky part here is that signals are registered in the Unix event # loop with a wakeup fd, but another application could have registered # signals using signal.signal directly. For now, the implementation is # hard-coded for the `asyncio.unix_events._UnixSelectorEventLoop`. # No WINCH? Then don't do anything. sigwinch = getattr ( signal , "SIGWINCH" , None ) if sigwinch is None or not in_main_thread ( ) : yield return # Keep track of the previous handler. # (Only UnixSelectorEventloop has `_signal_handlers`.) loop = get_event_loop ( ) previous_winch_handler = getattr ( loop , "_signal_handlers" , { } ) . get ( sigwinch ) try : loop . add_signal_handler ( sigwinch , handler ) yield finally : # Restore the previous signal handler. loop . remove_signal_handler ( sigwinch ) if previous_winch_handler is not None : loop . add_signal_handler ( sigwinch , previous_winch_handler . _callback , * previous_winch_handler . _args , )