mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-27 01:40:20 +08:00
Merge pull request #71 from gradio-app/abidlabs/windows
changed to daemon thread
This commit is contained in:
commit
7eb0cdb1d4
@ -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:
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user