code: def _upgrade_broker(broker):
      
      # This function is deadly! The act of calling start_receive() generates log
      # messages which must be silenced as the upgrade progresses, otherwise the
      # poller state will change as it is copied, resulting in write fds that are
      # lost. (Due to LogHandler->Router->Stream->Broker->Poller, where Stream
      # only calls start_transmit() when transitioning from empty to non-empty
      # buffer. If the start_transmit() is lost, writes from the child hang
      # permanently).
      root = logging.getLogger()
      old_level = root.level
      root.setLevel(logging.CRITICAL)
  
      old = broker.poller
      new = PREFERRED_POLLER()
      for fd, data in old.readers:
          new.start_receive(fd, data)
      for fd, data in old.writers:
          new.start_transmit(fd, data)
  
      old.close()
      broker.poller = new
      root.setLevel(old_level)
      LOG.debug('replaced %r with %r (new: %d readers, %d writers; '
                'old: %d readers, %d writers)', old, new,
                len(new.readers), len(new.writers),
                len(old.readers), len(old.writers))
docs: Extract the poller state from Broker and replace it with the industrial
      strength poller for this OS. Must run on the Broker thread.