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

在 uwsgi/gunicorn 多进程的环境中,在阻塞请求的情况下,如何去获取 os.popen()、subprocess.Poen() 的回调信息

  •  
  •   miniyao · Aug 27, 2018 · 2265 views
    This topic created in 2951 days ago, the information mentioned may be changed or developed.
    有一个任务大约耗时 1~3 秒钟左右,所以考虑先阻塞请求( 1~3 秒的等待可以接受),等任务执行完,返回完成信息之后,在进行下一步。由于 uwsgi/gunicorn 多个 worker, 须要获取 os.popen()、subprocess.Poen() 方法 fork 出的进程 id、以及状态返回值,异常的时候父进程还要能 kill 子进程。

    在单进程的情况下,按上面的思路可以行的通。但是多进程的时候,就各种信息捕获异常。想要在多 woker 的环境中,阻塞请求,还能优雅的能获取子进程的回调信息呢?还是上面的思路本身有问题?
    2 replies  •  2018-08-27 20:33:27 +08:00
    yufpga
        1
    yufpga  
       Aug 27, 2018   ❤️ 1
    不知道你用的是哪一个 py2 还是 py3。可以看一下这个链接 https://pymotw.com/3/subprocess/index.html,针对 python3 的 subprocess。这个包和 py2 中有一些不一样,可以看一下 subprocess.run 这个函数的源码,它是通过封装 subprocess.Popen 来的,里面包含了各种异常处理, 可以参考一下.
    lolizeppelin
        2
    lolizeppelin  
       Aug 27, 2018 via Android
    waitpid
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2652 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:30 · PVG 21:30 · LAX 06:30 · JFK 09:30
    ♥ Do have faith in what you're doing.