def before_first_request():
"""Start a background thread that looks for users that leave."""
def find_offline_users(app):
with app.app_context():
while True:
users = User.find_offline_users()
for user in users:
push_model(user)
db.session.remove()
time.sleep(5)
if not current_app.config['TESTING']:
thread = threading.Thread(target=find_offline_users,
args=(current_app._get_current_object(),))
thread.start()
评论列表
文章目录