3

2つの異なるポートでリッスンするFlaskインスタンスを実行したいのですが、つまり、ポート8080での操作と、8090での操作があります。これを行う方法はありますか?スレッドで2つのFlaskアプリインスタンスを実行している可能性がありますか?

コンテキストの追加:基本的に、コア機能がポート8080にある本番環境をエミュレートする必要がありますが、セキュリティ上の制限があるため、特定のクライアントの一部の操作(8090)にプロキシを使用する必要があります

たとえば8080を意味します

  • / repository / {id}

この操作はほとんどすべてのクライアントによって消費されますが、一部の特定のクライアントはプロキシを使用する必要があります。たとえば8090で

  • / reposproxy?method = "get"&resource = "repository"&query = "id =" xxxx "

基本的には8080と呼びます。

さらに、app.run()のスレッドをフォークまたは作成しようとしましたが、実行に成功しませんでした。

4

1 に答える 1

2

マルチプロセッシングPython機能を使用したFork(プロセス)アプローチを使用して解決しました。私はFlaskをアプリに定義してから、実行して処理します

def info(title):
    print(title)
    print('module name:', __name__)
    if hasattr(os, 'getppid'):  # only available on Unix
        print('parent process:', os.getppid())
    print('process id:', os.getpid())


def startServer(inDebug, port):
    print "Starting Main Mock Server"
    app.run(debug=inDebug, port=port)


def startProxyServer(inDebug, port):
    print "Starting JSONP Mock Server Proxy"
    appJsonp.run(debug=inDebug, port=jsonpPort)


if __name__ == '__main__':
    info('Main Line Starting')
    p = mp.Process(target=startServer, args=(False, port))
    p.deamon = True
    p.start()
    p1 = mp.Process(target=startProxyServer, args=(False, port))
    p1.deamon = True
    p1.start()
    p.join()
    p1.join()
于 2012-12-17T20:32:27.430 に答える