How to run another python code in backgroud with flask

@app.route('/result/<case_id>')
def result(case_id):
     USER_FOLDER = os.path.join(UPLOAD_FOLDER + '/' + Case_ID)          
     Analysis_code.main(USER_FOLDER, Case_ID, Case_ID + '_mRNA_file.txt', Case_ID + '_lncRNA_file.txt', Case_ID + '_miRNA_file.txt')

     return render_template('test.html',case_id=Case_ID)

In my this result route, I call a function that are from another file.But when flask executed Analysis_code.main() ,it didn't have enough time to run through the code.

In my Analysis_code.main(),the correlation def seemed like doesn't finish the save file job,and server return gateway timout error back.

def main():
    correlation(PATH, CASE_ID, mRNA_file_name, lncRNA_file_name, miRNA_file_name)
    bipartite_network(PATH, CASE_ID)

Is there any way to solve this problem? I've searched about subprocess, but it seems like it's not suitable for me.

I am trying to figure out how to return the render_template and the def call from another python code can still finish in the backgroud. Now, render_template has to wait for the function call finish so that it can return the webpage

链接地址: http://www.djcxy.com/p/71902.html

上一篇: 如何获取Flask请求中收到的数据

下一篇: 如何在烧瓶背景中运行另一个python代码