Execute task once when starting uwsgi
I'm using uwsgi-emperor on Debian 8 in my production systems. For a specific Django project, I need to run a computing intensive setup task only once at the launch of the vassal. The vassal can have multiple workers/threads, but the task must be executed only one time, no matter how many workers/threads are spawned.
Currently, I'm executing this setup task every time a new worker is launched, but this is clearly suboptimal. The setup task is an invocation of a method from the same Django project, but I think that doesn't change the problem.
Is there any way of doing this from uWSGI?
您可以尝试使用singletone方法,settings.py中的此代码只会调用一次startup_only_once()函数:
from tendo.singleton import SingleInstance
def startup_only_once():
print("One time only")
try:
FIRST_START = SingleInstance()
startup_only_once()
except:
pass
链接地址: http://www.djcxy.com/p/65946.html
上一篇: IE7导致“文字”
下一篇: 启动uwsgi时执行一次任务