From d5ccd8177ef739b66e0c014693e5e92c084d6e3e Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Mon, 19 Oct 2020 08:07:39 -0500 Subject: [PATCH] changed to daemon thread --- gradio/interface.py | 8 ++------ gradio/networking.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gradio/interface.py b/gradio/interface.py index 094445734d..e461d92861 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -20,11 +20,7 @@ import copy analytics.write_key = "uxIFddIEuuUcFLf9VgH2teTEtPlWdkNy" analytics_url = 'https://api.gradio.app/' -try: - ip_address = requests.get('https://api.ipify.org').text -except requests.ConnectionError: - ip_address = "No internet connection" - +ip_address = networking.get_local_ip_address() class Interface: """ @@ -303,7 +299,7 @@ class Interface: except (KeyboardInterrupt, OSError): print("Keyboard interruption in main thread... closing server.") thread.keep_running = False - networking.url_ok(path_to_local_server) + networking.url_ok(path_to_local_server) # Hit the server one more time to close it def test_launch(self): for predict_fn in self.predict: diff --git a/gradio/networking.py b/gradio/networking.py index 2c69fb267c..3890db134a 100644 --- a/gradio/networking.py +++ b/gradio/networking.py @@ -55,6 +55,14 @@ def set_config(config): app.app_globals["config"] = config +def get_local_ip_address(): + try: + ip_address = requests.get('https://api.ipify.org').text + except requests.ConnectionError: + ip_address = "No internet connection" + return ip_address + + def get_first_available_port(initial, final): """ Gets the first open port in a specified range of port numbers @@ -173,9 +181,9 @@ def start_server(interface, server_name, server_port=None): app.cwd = os.getcwd() log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) - process = threading.Thread(target=app.run, kwargs={"port": port, "host": server_name}) - process.start() - return port, app, process + thread = threading.Thread(target=app.run, kwargs={"port": port, "host": server_name}, daemon=True) + thread.start() + return port, app, thread def close_server(process):