(2018-11-13, 15:57)Roman_V_M Wrote: There is no such thing as "Flask server". Flask web-framework uses external WSGI servers to run, and for simple cases you can use Python's built-in WSGIref server. But your server needs to be gratefully shut down on Kodi exit. Kodi itself also includes a WSGI server but I'm afraid it's not well documented.
Here's an example from one of my old addons: https://github.com/romanvm/kodi.yatp/blo...ver.py#L47
It runs a Bottle web-app, but the general principle is the same.
It's very simple server with just 50 lines of code.
I found some example of wsgiref, here is the code:
python:
from cgi import parse_qs
from wsgiref.simple_server import make_server
def simple_app(environ, start_response):
status = '200 OK'
headers = [('Content-Type', 'text/plain')]
start_response(status, headers)
if environ['REQUEST_METHOD'] == 'POST':
request_body_size = int(environ.get('CONTENT_LENGTH', 0))
request_body = environ['wsgi.input'].read(request_body_size)
d = parse_qs(request_body) # turns the qs to a dict
return 'From POST: %s' % ''.join('%s: %s' % (k, v) for k, v in d.iteritems())
else: # GET
d = parse_qs(environ['QUERY_STRING']) # turns the qs to a dict
return 'From GET: %s' % ''.join('%s: %s' % (k, v) for k, v in d.iteritems())
httpd = make_server('', 1337, simple_app)
print "Serving on port 1337..."
httpd.serve_forever()
it works but i can't run anything else, it's just spinning circle and doesn't load code after httpd.serve_forever(). How would i run this in background so everything else would work fine? I am guessing with threads, but maybe there is some other way.
EDIT: It looks like a manage to run it on thread and at least for everything works fine