From bd27353a08df9896ef6b560cde7e3dcb33b7d67d Mon Sep 17 00:00:00 2001 From: Maya <48323879+mayaeary@users.noreply.github.com> Date: Sun, 19 Mar 2023 12:51:27 +0000 Subject: [PATCH] Fix duplicating server on ui reload --- extensions/api/script.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extensions/api/script.py b/extensions/api/script.py index 53e47f3f..1c57c72a 100644 --- a/extensions/api/script.py +++ b/extensions/api/script.py @@ -8,6 +8,8 @@ params = { 'port': 5000, } +server = None + class Handler(BaseHTTPRequestHandler): def do_GET(self): if self.path == '/api/v1/model': @@ -73,6 +75,7 @@ class Handler(BaseHTTPRequestHandler): def run_server(): + global server server_addr = ('0.0.0.0' if shared.args.listen else '127.0.0.1', params['port']) server = ThreadingHTTPServer(server_addr, Handler) if shared.args.share: @@ -87,4 +90,5 @@ def run_server(): server.serve_forever() def ui(): - Thread(target=run_server, daemon=True).start() \ No newline at end of file + if server is None: + Thread(target=run_server, daemon=True).start() \ No newline at end of file