1

I run another gtk window to show my application, in the same time I want to run Flask.run(host:'0.0.0.0'). Flask still processing when I close my gtk.window that run my app. Can anybody help?

here is the code :

import multiprocessing
import opx
import app

def worker(file):
    if file == 'opx':
    opx.main()
    else :
    app.apx.run(host='0.0.0.0') 

if __name__ == '__main__':
    files = ["opx","app.py"]
    for i in files:
        p = multiprocessing.Process(target=worker(i))
        p.start()
    p.join()
Frank AK
  • 1,705
  • 15
  • 28
Donald Wengki
  • 29
  • 1
  • 6
  • Why `multiprocessing`, Have you considered deploy it on `tornado` or `gevent` ? – Frank AK Nov 19 '17 at 07:36
  • Hai Frank, thank you for your respond. I already try it on tornado but I still stuck with it. Can you give me an example? I'm new of python... – Donald Wengki Nov 20 '17 at 09:53

1 Answers1

4

There are several combinations here:

from flask import Flask
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    http_server = HTTPServer(WSGIContainer(app))
    http_server.listen(8000)
    IOLoop.instance().start()

Flask with Gevent

Flask with Tornado

You should do more research before asked question. (Because of repeated problems can lead to confusion in the community)

Frank AK
  • 1,705
  • 15
  • 28