From: peusterm Date: Tue, 19 Mar 2019 16:05:57 +0000 (+0100) Subject: Fix: Changed LLCM to use gevent X-Git-Tag: v6.0.0~15 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F32%2F7332%2F1;p=osm%2Fvim-emu.git Fix: Changed LLCM to use gevent Change-Id: I232e529cd0b35614c697e9c41d12b9b62955a87a Signed-off-by: peusterm --- 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):