From f8f135c271341479200232641823520a541f33b0 Mon Sep 17 00:00:00 2001 From: peusterm Date: Tue, 19 Mar 2019 17:05:57 +0100 Subject: [PATCH] Fix: Changed LLCM to use gevent Change-Id: I232e529cd0b35614c697e9c41d12b9b62955a87a Signed-off-by: peusterm --- src/emuvim/api/tango/__init__.py | 3 +++ src/emuvim/api/tango/llcm.py | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/emuvim/api/tango/__init__.py b/src/emuvim/api/tango/__init__.py index 3fe6a16..ea3bc54 100755 --- a/src/emuvim/api/tango/__init__.py +++ b/src/emuvim/api/tango/__init__.py @@ -72,3 +72,6 @@ class TangoLLCMEndpoint(object): def _api_server_thread(self): llcm.start_rest_api(self.ip, self.port, self.dcs) + + def stop(self): + llcm.stop_rest_api() diff --git a/src/emuvim/api/tango/llcm.py b/src/emuvim/api/tango/llcm.py index aae6be1..eaa0b5e 100755 --- a/src/emuvim/api/tango/llcm.py +++ b/src/emuvim/api/tango/llcm.py @@ -39,6 +39,7 @@ import threading from docker import DockerClient from flask import Flask, request import flask_restful as fr +from gevent.pywsgi import WSGIServer from subprocess import Popen import ipaddress import copy @@ -1028,6 +1029,7 @@ def initialize_GK(): GK = None initialize_GK() # setup Flask +http_server = None app = Flask(__name__) app.config['MAX_CONTENT_LENGTH'] = 512 * 1024 * 1024 # 512 MB max upload api = fr.Api(app) @@ -1039,14 +1041,22 @@ api.add_resource(Exit, '/emulator/exit') def start_rest_api(host, port, datacenters=dict()): + global http_server GK.dcs = datacenters GK.net = get_dc_network() # start the Flask server (not the best performance but ok for our use case) - app.run(host=host, - port=port, - debug=True, - use_reloader=False # this is needed to run Flask in a non-main thread - ) + # app.run(host=host, + # port=port, + # debug=True, + # use_reloader=False # this is needed to run Flask in a non-main thread + # ) + http_server = WSGIServer((host, port), app, log=open("/dev/null", "w")) + http_server.serve_forever() + + +def stop_rest_api(): + if http_server: + http_server.close() def ensure_dir(name): -- 2.25.1