{"record":{"id":"9b8196e7e952057c","repo":"mlflow/mlflow","slug":"served-pyfunc-model-is-missing-server-process-id","errorCode":null,"errorMessage":"Served PyFunc Model is missing server process ID.","messagePattern":"Served PyFunc Model is missing server process ID\\.","errorType":"exception","errorClass":"MlflowException","httpStatus":null,"severity":"error","filePath":"mlflow/pyfunc/__init__.py","lineNumber":1244,"sourceCode":"            data: Model input data.\n            params: Additional parameters to pass to the model for inference.\n\n        Returns:\n            Model predictions.\n        \"\"\"\n        if \"params\" in inspect.signature(self._client.invoke).parameters:\n            result = self._client.invoke(data, params=params).get_predictions()\n        else:\n            _log_warning_if_params_not_in_predict_signature(_logger, params)\n            result = self._client.invoke(data).get_predictions()\n        if isinstance(result, pandas.DataFrame):\n            result = result[result.columns[0]]\n        return result\n\n    @property\n    def pid(self):\n        if self._server_pid is None:\n            raise MlflowException(\"Served PyFunc Model is missing server process ID.\")\n        return self._server_pid\n\n    @property\n    def env_manager(self):\n        return self._env_manager\n\n    @env_manager.setter\n    def env_manager(self, value):\n        self._env_manager = value\n\n\ndef _load_model_or_server(\n    model_uri: str, env_manager: str, model_config: dict[str, Any] | None = None\n):\n    \"\"\"\n    Load a model with env restoration. If a non-local ``env_manager`` is specified, prepare an\n    independent Python environment with the training time dependencies of the specified model\n    installed and start a MLflow Model Scoring Server process with that model in that environment.","sourceCodeStart":1226,"sourceCodeEnd":1262,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/pyfunc/__init__.py#L1226-L1262","documentation":"`_ServedPyFuncModel.pid` returns the OS process ID of the scoring-server subprocess, stored in `_server_pid`. If the server process was never started or its PID was never recorded (None), accessing `.pid` raises MlflowException rather than returning None.","triggerScenarios":"Accessing `.pid` on a `_ServedPyFuncModel` that was constructed without a running server process — e.g. the server failed to launch, was already torn down, or the object was created directly with server_pid=None.","commonSituations":"Inspecting `.pid` after a failed model-server launch; accessing `.pid` on a served-model object obtained via `mlflow.pyfunc.load_model(..., env_manager=...)` after the server exited or before it started; race with server shutdown.","solutions":["Only access `.pid` while the served model is running and healthy (e.g. after a successful predict call)","Check `_server_pid is not None` before reading `.pid`","If the server failed to launch, first diagnose the launch failure (see the 'failed to launch' error) and re-invoke load_model with env_manager","Re-create the served model via `mlflow.pyfunc.load_model(model_uri, env_manager='uv')`"],"exampleFix":"// before\npid = served.pid  # raises if server missing\n// after\nif served._server_pid is not None:\n    pid = served.pid","handlingStrategy":"type-guard","validationCode":"if served_model._server_pid is None:\n    raise RuntimeError(\"scoring server is not running; cannot get pid\")","typeGuard":"def server_is_running(served) -> bool:\n    import psutil\n    return served._server_pid is not None and psutil.pid_exists(served._server_pid)","tryCatchPattern":"try:\n    pid = served.pid\nexcept MlflowException:\n    pid = None  # server not launched or already terminated\n    restart_server()","preventionTips":["Only access .pid while the served model is live","Confirm load_model with env_manager completed successfully first","Check server health (predict round-trip) before inspecting pid","Guard against races with server shutdown"],"tags":["pyfunc","serving","process-management"],"backgroundTag":"missing-process-id","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}