我有一个问题,那就是Django可以执行多线程工作吗?
这是我要执行的操作:单击网页上的按钮,然后model.py中开始运行某些功能,例如,从Internet上爬网一些数据,完成后它将返回给用户结果。
我想知道我必须打开一个新线程来执行model.py中的功能,有人可以告诉我该怎么做吗?非常感谢你。
User sends request Django receives => spawns a thread to do something else. main thread finishes && other thread finishes ... (later upon completion of both tasks) response is sent to user as a package.
更好的方法:
User sends request Django receives => lets Celery know "hey! do this!" main thread finishes response is sent to user ...(later) user receives balance of transaction