code: def display_manager(display):
      
      from contextlib import contextmanager
  
      @contextmanager
      def manager():
          errors = []
  
          def handler(*args):
              errors.append(args)
  
          old_handler = display.set_error_handler(handler)
          yield display
          display.sync()
          display.set_error_handler(old_handler)
          if errors:
              raise X11Error(errors)
  
      return manager()
docs: Traps *X* errors and raises an :class:``X11Error`` at the end if any
      error occurred.
  
      This handler also ensures that the :class:`Xlib.display.Display` being
      managed is sync'd.
  
      :param Xlib.display.Display display: The *X* display.
  
      :return: the display
      :rtype: Xlib.display.Display