Skip to content

Commit

Permalink
Only set multiprocessing start method if it is not already set
Browse files Browse the repository at this point in the history
Signed-off-by: Sivanantham Chinnaiyan <sivanantham.chinnaiyan@ideas2it.com>
  • Loading branch information
sivanantha321 committed Feb 7, 2024
1 parent d977cc0 commit 6f0768c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions python/kserve/kserve/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ def __str__(self):
return self.error_msg


class UnsupportedProcessStartMethod(RuntimeError):
def __init__(self, start_method: str):
self.error_msg = f"Unsupported multi processing start method '{start_method}'. Only 'fork' is supported."

def __str__(self):
return self.error_msg


async def exception_handler(_, exc):
logger.error("Exception:", exc_info=exc)
return JSONResponse(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, content={"error": str(exc)})
Expand Down
8 changes: 7 additions & 1 deletion python/kserve/kserve/model_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from ray.serve.api import Deployment
from ray.serve.handle import RayServeHandle

from .errors import UnsupportedProcessStartMethod
from .logging import KSERVE_LOG_CONFIG, logger
from .model import Model
from .model_repository import ModelRepository
Expand Down Expand Up @@ -203,7 +204,12 @@ async def serve():
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
serversocket.bind(('0.0.0.0', self.http_port))
serversocket.listen(5)
multiprocessing.set_start_method('fork')
start_method = multiprocessing.get_start_method(allow_none=True)
if start_method is None:
logger.info("Setting 'fork' as multiprocessing start method.")
multiprocessing.set_start_method('fork')
elif start_method in ['spawn', 'forkserver']:
raise UnsupportedProcessStartMethod(start_method)
self._rest_server = UvicornServer(self.http_port, [serversocket],
self.dataplane, self.model_repository_extension,
self.enable_docs_url, log_config=self.log_config,
Expand Down

0 comments on commit 6f0768c

Please sign in to comment.