send analytics on background thread

This commit is contained in:
dawoodkhan82 2020-07-14 12:17:46 -04:00
parent efdcabf6a5
commit 064aef5772

View File

@ -116,6 +116,17 @@ def get_first_available_port(initial, final):
)
)
def send_prediction_analytics(interface):
data = {'input_interface': interface.input_interfaces,
'output_interface': interface.output_interfaces,
}
try:
requests.post(
analytics_url + 'gradio-prediction-analytics/',
data=data)
except requests.ConnectionError:
pass # do not push analytics if no network
def serve_files_in_background(interface, port, directory_to_serve=None, server_name=LOCALHOST_NAME):
class HTTPHandler(SimpleHTTPRequestHandler):
@ -160,17 +171,11 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n
# f.write(json.dumps(output_flag))
# f.write("\n")
# Prepare return json dictionary.
self.wfile.write(json.dumps(output).encode())
data = {'input_interface': interface.input_interfaces,
'output_interface': interface.output_interfaces,
}
try:
requests.post(
analytics_url + 'gradio-prediction-analytics/',
data=data)
except requests.ConnectionError:
pass # do not push analytics if no network
analytics_thread = threading.Thread(
target=send_prediction_analytics, args=[interface])
analytics_thread.start()
elif self.path == "/api/flag/":
self._set_headers()