code: def _setup_pailgun(self):
      
      # Constructs and returns a runnable PantsRunner.
      def runner_factory(sock, arguments, environment):
        return self._runner_class.create(
          sock,
          arguments,
          environment,
          self.services,
          self._scheduler_service,
        )
  
      # Plumb the daemon's lifecycle lock to the `PailgunServer` to safeguard teardown.
      # This indirection exists to allow the server to be created before PantsService.setup
      # has been called to actually initialize the `services` field.
      @contextmanager
      def lifecycle_lock():
        with self.services.lifecycle_lock:
          yield
  
      return PailgunServer(self._bind_addr, runner_factory, lifecycle_lock, self._request_complete_callback)
docs: Sets up a PailgunServer instance.