推荐学习书目
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
chuanqirenwu
V2EX  ›  Python

在一段 Python 代码中异步启动另一个 Python 脚本,应该怎么做?

  •  
  •   chuanqirenwu · Jul 30, 2018 via iPad · 3276 views
    This topic created in 2928 days ago, the information mentioned may be changed or developed.
    需求是这样的,我有一个 python 脚本,这个脚本包含一段无限循环执行的代码。现在我使用 django 开发控制脚本执行的功能,即前端发送一个请求给服务器,django 接收到这个请求就停止那个无限循环的脚本,修改那个脚本的配置参数后再重启这段脚本,恢复其运行状态。

    现在的问题就是不知道该如何停止脚本以及重启脚本,网上搜了一些解决方案似乎没有奏效。希望有经验的前辈能够指点指点,小弟在此先谢过啦。
    5 replies    2018-08-06 09:00:19 +08:00
    kimqcn
        1
    kimqcn  
       Jul 30, 2018
    启:
    ps1=Process(target=my_func)

    停:
    os.kill(ps1.pid, signal.SIGKILL)
    Arnie97
        2
    Arnie97  
       Jul 31, 2018 via Android
    Werkzeug ( Flask )有代码改变时重启自身的功能,你不妨阅读一下源码。
    vimiix
        3
    vimiix  
       Aug 1, 2018
    Celery 了解一下
    RicardoScofileld
        4
    RicardoScofileld  
       Aug 1, 2018
    celery
    bwangel
        5
    bwangel  
       Aug 6, 2018
    celery 执行的是定时任务,况且 celery 执行后也没法控制啊,只能等着结束。

    请问你说的 django 开发控制脚本的意思是写了个脚本执行了 django.setup 函数吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   965 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 21:57 · PVG 05:57 · LAX 14:57 · JFK 17:57
    ♥ Do have faith in what you're doing.