def start()

in tensorflow/inference/docker/build_artifacts/sagemaker_neuron/serve.py [0:0]


    def start(self):
        log.info("starting services")
        log.info("NEURONCORE_GROUP_SIZES {}".format(self._user_ncgs))
        log.info("SAGEMAKER_GUNICORN_WORKERS {}".format(self._gunicorn_workers))
        self._state = "starting"
        signal.signal(signal.SIGTERM, self._stop)

        if self._tfs_enable_multi_model_endpoint:
            log.info("multi-model endpoint is enabled, TFS model servers will be started later")
        else:
            self._create_tfs_config()
            #Start TFS workers for each gunicorn worker
            for tf_worker_num in range(int(self._gunicorn_workers)):
                self._start_tfs()
            print("all TFS PIDs {}".format(self._tfs))

        self._create_nginx_config()

        if self._tfs_enable_batching:
            log.info("batching is enabled")
            tfs_utils.create_batching_config(self._tfs_batching_config_path)

        if self._use_gunicorn:
            self._setup_gunicorn()
            self._start_gunicorn()
            # make sure gunicorn is up
            with self._timeout(seconds=30):
                self._wait_for_gunicorn()

        self._start_nginx()
        self._state = "started"

        while True:
            pid, status = os.wait()

            if self._state != "started":
                break

            if pid == self._nginx.pid:
                log.warning("unexpected nginx exit (status: {}). restarting.".format(status))
                self._start_nginx()

            elif pid in self._tfs:
                log.warning(
                    "unexpected tensorflow serving exit (status: {}). restarting.".format(status))
                self._tfs.remove(pid)
                self._start_tfs()

            elif self._gunicorn and pid == self._gunicorn.pid:
                log.warning("unexpected gunicorn exit (status: {}). restarting."
                            .format(status))
                self._start_gunicorn()

        self._stop()