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

python 子进程输出怎么用模板显示出来?

  •  
  •   xuyl · Nov 3, 2015 · 2741 views
    This topic created in 3978 days ago, the information mentioned may be changed or developed.

    关于 flask 的模板渲染问题: render_template()

    我的程序是这样写的

    @app.route('/haha')
    def run_haha():
    p = subprocess.Popen('python /home/test.py',shell=True,stdout=subprocess.PIPE)
    c = p.stdout.readline()
    while p.poll() == None:
    return render_template('haha.html',cout = p.stdout.readline())

    我希望把调用子进程的输出作为参数,用模板渲染出来。结果发现,由于子进程(test.py)输出数据量过大,导致程序卡死。 各位大神,你们有什么好的办法处理这种需求?

    3 replies  •  2015-11-03 18:48:10 +08:00
    yangtukun1412
        1
    yangtukun1412  
       Nov 3, 2015
    如果输出的数据量真那么大,你渲染成 html 也一样打不开...
    wayslog
        2
    wayslog  
       Nov 3, 2015
    我觉得你还是把 test.py 里面的数据输出到文件里然后提供文件下载吧……
    xuyl
        3
    xuyl  
    OP
       Nov 3, 2015
    @yangtukun1412 实时监控用的,我看到 celery 能异步处理长任务。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2403 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:44 · PVG 13:44 · LAX 22:44 · JFK 01:44
    ♥ Do have faith in what you're doing.