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

[求助] mod_wsgi 中调用 function 或 .py 并完全脱离主进程

  •  
  •   terence4444 · Mar 23, 2016 · 2679 views
    This topic created in 3838 days ago, the information mentioned may be changed or developed.
    需要一个公众号功能,我需要多执行一会时间,但由于微信有响应时间要求,不然服务器会发三遍请求。
    设想是先返回一个 success 给微信服务器,并在新进程里继续执行到完成为止。
    也就是在 mod_wsgi 中调用某个 function 或者 subprocess.Popen 一个 .py 文件并完全脱离主进程运行。

    要求:
    第一步:接收信息
    第二步:调用 function
    第三步:返回空信息
    第四步:主进程结束处理( function 仍在继续运行,结束后自行退出)

    尝试:
    1. 直接调用 function :由于第二步执行时间过长,微信服务器发 N 遍请求过来,导致重复执行。
    2. 使用 subprocess.Popen 一个 .py 文件,在 .py 文件中调用那个 funtion 。主进程会等待 subprocess 返回,和 1. 的效果一样。
    3. 使用 multiprocessing.Process target = function 这个更糟,不但不会继续执行第三步,还会弹出 Apache 的 httpd.exe ,调用一次 Process 弹一个新 httpd.exe
    4. 使用 multiprocessing.Pool 和 3 一样,进程池有多大就开几个 httpd.exe
    4 replies  •  2016-03-23 17:38:33 +08:00
    virusdefender
        1
    virusdefender  
       Mar 23, 2016 via Android   ❤️ 1
    你需要的是异步队列 celery 或者 rq
    terence4444
        2
    terence4444  
    OP
       Mar 23, 2016 via iPhone
    @virusdefender 感谢 回头我再试试
    ljdawn
        3
    ljdawn  
       Mar 23, 2016 via iPhone   ❤️ 1
    subprocess
    terence4444
        4
    terence4444  
    OP
       Mar 23, 2016 via iPhone
    @ljdawn 在 wsgi 里 subprocess 好像不一样…
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2419 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:02 · PVG 13:02 · LAX 22:02 · JFK 01:02
    ♥ Do have faith in what you're doing.