django linux 环境下函数设置超时

使用timeout-decorator

  • pip install timeout-decorator
import time
import timeout_decorator

@timeout_decorator.timeout(3, use_signals=False) #如果改为 True   会报signal only works in main thread(错误),这个后台是使用multiprocessing 实现的
def mytest():
    time.sleep(5)
    return 5
mytest()

在 django 中使用 signals 可以查看 https://stackoverflow.com/questions/8572830/pythondjango-signal-handler-and-main-thread
本文参考:https://www.jianshu.com/p/a7fc98c7af4d

posted @ 2020-08-24 10:30  呦吼吼吼~  阅读(242)  评论(0编辑  收藏  举报