在diango1.10中,设置一个时间来做signal.post_save.connection()

时间:2016-11-16 11:54:17

标签: python django

在diango1.10中,当从网站上传图像文件时,数据库将插入一条记录,其中有一个项目是" is_execute",如果不是,该图像文件将由一个函数执行。我使用signals.post_save.connetion(),但我不想立即这样做,我希望这个功能可以在午夜执行

def an_update(sender, instance, **kwargs):
#path = os.path.join('/', os.path.dirname(__file__),instance.headImg.name)
#print path
if instance.is_excuted == False:
    instance.is_excuted = True
    instance.final_score = 0.5
    path = os.path.join('/root/myweb_vipa/upload/upload/',instance.headImg.name)
    cmd = '/home/yunshen/Ammeter_detection/ammeter_detection '+path+" "+instance.headImg.name
    subprocess.call(cmd,shell=True)
    instance.save()
    return 0

signals.post_save.connect(an_update,sender = User)

1 个答案:

答案 0 :(得分:3)

这不是信号的作用。

信号只是解耦逻辑的一种方式。它们不会在进程外运行;没有办法推迟他们。

如果您需要此功能,则应使用Celery之类的内容。