Flask使父进程中的代码执行两次

时间:2020-03-02 17:39:09

标签: python flask anaconda multiprocessing python-multiprocessing

我的Python程序在子进程上创建一个flask服务器。但是,父进程中的其余代码然后执行两次。谁能向我解释为什么会这样?

来源:

rd_family_title

输出:

from multiprocessing import Process
from flask import Flask

class Server():
    def __init__(self):
        app = Flask(__name__)
        app.run(debug=True)
        print("This code is executed twice after a KeyboardInterrupt")

def main():
    p_server = Process(target=Server)
    p_server.start()

    print("This code in parent process is executed twice")

if __name__ == "__main__":
    main()

0 个答案:

没有答案