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
miniyao
V2EX  ›  Python

怎样在生产环境中(gunicorn 起多个进程),还能使用 os.system 或 subprocess 命令?

  •  
  •   miniyao · 2018-05-10 09:47:42 +08:00 · 3155 次点击
    这是一个创建于 2176 天前的主题,其中的信息可能已经有所发展或是发生改变。
    本地开发环境中 os.system 和 subprocess 都是正常执行的,但是在生产环境中,gunicorn 起了多个 worker,os.system 和 subprocess 这样的任务就全失效了。

    怎样才能在 gunicorn 多进程的环境中,还能使用这种 fork 进程的 os.system 或 subprocess 命令?
    8 条回复    2018-05-10 22:57:46 +08:00
    ebingtel
        1
    ebingtel  
       2018-05-10 12:55:54 +08:00
    有这种说法?
    meik2333
        2
    meik2333  
       2018-05-10 16:41:54 +08:00
    应该不会吧……要不试试 celery
    a132811
        3
    a132811  
       2018-05-10 17:06:20 +08:00
    试了下 os.system('ls -l') 没有问题啊!

    你把日志打开看看,我的都有
    --log-file gun.log --capture-output
    julyclyde
        4
    julyclyde  
       2018-05-10 17:17:19 +08:00
    不会失效
    wzwwzw
        5
    wzwwzw  
       2018-05-10 18:47:43 +08:00
    要不试试 pool ?
    applehater
        6
    applehater  
       2018-05-10 21:36:27 +08:00
    用个 pid 文件记录进程不让他重复启动就好
    @a132811
    @julyclyde gunicorn 多个 worker 会把子进程也启动多次
    julyclyde
        7
    julyclyde  
       2018-05-10 22:18:54 +08:00   ❤️ 1
    @applehater 多次那是你没理解 gunicorn 是怎么运行的,那是你自己的问题
    param
        8
    param  
       2018-05-10 22:57:46 +08:00 via Android
    不會失效,我也是這麼用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1298 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:32 · PVG 07:32 · LAX 16:32 · JFK 19:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.