【发布时间】:2020-12-24 05:08:21
【问题描述】:
我有以下代码用于测试在 heroku 上使用烧瓶运行两个线程。
app.py
from flask import Flask, render_template
import threading
import time
import sys
app = Flask(__name__, static_url_path='')
test_result = 'failed'
@app.route('/')
def index():
return 'Hello! Server is running'
@app.route('/thread-test')
def thread_test():
global test_result
return test_result
def thread_testy():
time.sleep(10)
global test_result
test_result = 'passed'
return
if __name__ == "__main__":
threading.Thread(target=app.run).start()
threading.Thread(target=thread_testy).start()
程序
web: gunicorn app:app --log-file=-
这在本地返回“通过”,但在 Heroku 上返回“失败”。有人对如何让这个测试起作用有任何想法吗?
【问题讨论】:
标签: python multithreading flask heroku