def restart(self):
    with self._instances_change_lock:
      with self._condition:
        if self._quit_event.is_set():
          return
        instances_to_stop = self._instances[:]
        wsgi_servers = self._wsgi_servers[:]
      instances_to_start = []
      for instance_id, wsgi_servr in enumerate(wsgi_servers):
        inst = self._instance_factory.new_instance(instance_id,
                                                   expect_ready_request=True)
        wsgi_servr.set_app(functools.partial(self._handle_request, inst=inst))
        self._port_registry.add(wsgi_servr.port, self, inst)
        instances_to_start.append(inst)
      with self._condition:
        if self._quit_event.is_set():
          return
        self._instances[:] = instances_to_start

    # Just force instances to stop for a faster restart.
    for inst in instances_to_stop:
      inst.quit(force=True)

    start_futures = [
        self._async_start_instance(wsgi_servr, inst)
        for wsgi_servr, inst in zip(wsgi_servers, instances_to_start)]
    logging.info('Waiting for instances to restart')

    _, not_done = futures.wait(start_futures, timeout=_SHUTDOWN_TIMEOUT)
    if not_done:
      logging.warning('All instances may not have restarted')
    else:
      logging.info('Instances restarted')
Restarts the module, replacing all running instances.
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/tools/devappserver2/module.py/ManualScalingModule.restart