반응형
Flask REST API Threadding | Run task in background
https://www.youtube.com/watch?v=XrG_TlwPtsU
from flask import Flask
from flask_restful import Resource, Api
import time
import threading
import threading
app = Flask(__name__)
api = Api(app)
def task():
"""
background Process handled by Threads
:return: None
"""
print("Started Task ...")
print(threading.current_thread().name)
time.sleep(6)
print("completed .....")
class HelloWorld(Resource):
def get(self):
threading.Thread(target=task).start()
#task()
return {'hello': 'world'}
api.add_resource(HelloWorld, '/')
if __name__ == '__main__':
app.run(debug=True)
반응형
'Flask' 카테고리의 다른 글
Flask, The file/path provided (...) does not appear to exist 에러 (0) | 2022.06.18 |
---|---|
엘라스틱서치, 파이썬 Flask (0) | 2022.06.10 |
Python, Flask와 Oracle 데이터베이스 함께 사용하기 (Linux, Mac) (0) | 2022.01.14 |
플라스크, http 접속시 https로 리다이렉트 하기 (0) | 2021.11.14 |
점프 투 플라스크 (0) | 2021.10.07 |