Drkcore

11 01 2011 Python Flask Tweet

Flaskをthreadで動かす

MLより

  • Start/Stop Flask

multiprocessingを使えばいいらしい。

import time
from multiprocessing import Process
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
        return "Hi there!!!"

def run():
    app.run()

if __name__ == '__main__':

    app.debug = True

    print "starting process"
    server = Process(target=run)
    server.start()

    print "sleeping"
    time.sleep(5)

    print "ending process"
    server.terminate()
    server.join()

    print "bye..."

どういうシチュエーションでこういう必要性が出るのかいまいちわからんが覚えておこう。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021