From 565b05f02fc785a02855b2f596a5649a1bee7336 Mon Sep 17 00:00:00 2001 From: Byron Hsu Date: Sun, 6 Oct 2024 22:18:45 -0700 Subject: [PATCH] Use `atexit` hook to implicitly shutdown `Runtime` (#1595) --- python/sglang/srt/server.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/sglang/srt/server.py b/python/sglang/srt/server.py index c708d6f45..fb1bb8196 100644 --- a/python/sglang/srt/server.py +++ b/python/sglang/srt/server.py @@ -514,6 +514,9 @@ class Runtime: """See the arguments in server_args.py::ServerArgs""" self.server_args = ServerArgs(*args, log_level=log_level, **kwargs) + # before python program terminates, call shutdown implicitly. Therefore, users don't have to explicitly call .shutdown() + atexit.register(self.shutdown) + # Pre-allocate ports for port in range(10000, 40000): if is_port_available(port):