V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
hellowords
V2EX  ›  Python

问一个关于 django 的问题。

  •  
  •   hellowords · 2017-10-24 14:01:50 +08:00 · 1641 次点击
    这是一个创建于 2373 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如下这是我写的方法。如何让用户想开启就开启?想关闭就会自动关闭所有正在执行的操作。

    def monitor(request,url,enable=True):
    if enable:
    '''
    执行 monitor 监控,创建一个线程来执行监控函数。。不停的监控。
    '''
    return HttpResponse("开启完成")
    else:
    '''
    这里需要结束上面还在执行的线程该如果操作?
    '''
    return HttpResponse("关闭完成")
    1 条回复    2017-10-24 14:09:06 +08:00
    smgui
        1
    smgui  
       2017-10-24 14:09:06 +08:00
    数据库或者 cache 里给任务做标记,线程执行的过程中读取标记。
    如果标记为“关闭任务”则线程退出。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3041 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 422ms · UTC 00:32 · PVG 08:32 · LAX 17:32 · JFK 20:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.