From 39416e394affa25389eeaa4a2b277d7bc52f9713 Mon Sep 17 00:00:00 2001 From: Jiada Li <30839207+Jiadalee@users.noreply.github.com> Date: Sat, 15 Feb 2025 22:14:45 -0500 Subject: [PATCH] fix lockfile and port_registry file permission error (#3598) Co-authored-by: jiada li Co-authored-by: zhaochenyang20 --- python/sglang/utils.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/python/sglang/utils.py b/python/sglang/utils.py index c747eb5b2..d83022303 100644 --- a/python/sglang/utils.py +++ b/python/sglang/utils.py @@ -308,13 +308,31 @@ def download_and_cache_file(url: str, filename: Optional[str] = None): import fcntl -LOCKFILE = "/tmp/port_lock" -PORT_REGISTRY = "/tmp/port_registry.json" + +def is_in_ci(): + from sglang.test.test_utils import is_in_ci + + return is_in_ci() + + +LOCKFILE = os.path.expanduser("~/.sglang_port_lock") +PORT_REGISTRY = os.path.expanduser("~/.sglang_port_registry.json") + +if not os.path.exists(LOCKFILE): + with open(LOCKFILE, "w") as f: + pass + +if not os.path.exists(PORT_REGISTRY): + with open(PORT_REGISTRY, "w") as f: + json.dump([], f) def print_highlight(html_content: str): - html_content = str(html_content).replace("\n", "
") - display(HTML(f"{html_content}")) + if is_in_ci(): + html_content = str(html_content).replace("\n", "
") + display(HTML(f"{html_content}")) + else: + print(html_content) def init_port_registry():