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

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

  •  
  •   xuyl · 2015-11-03 14:35:10 +08:00 · 1966 次点击
    这是一个创建于 3103 天前的主题,其中的信息可能已经有所发展或是发生改变。

    关于 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 条回复    2015-11-03 18:48:10 +08:00
    yangtukun1412
        1
    yangtukun1412  
       2015-11-03 15:32:07 +08:00
    如果输出的数据量真那么大,你渲染成 html 也一样打不开...
    wayslog
        2
    wayslog  
       2015-11-03 18:19:48 +08:00
    我觉得你还是把 test.py 里面的数据输出到文件里然后提供文件下载吧……
    xuyl
        3
    xuyl  
    OP
       2015-11-03 18:48:10 +08:00
    @yangtukun1412 实时监控用的,我看到 celery 能异步处理长任务。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2096 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 01:45 · PVG 09:45 · LAX 18:45 · JFK 21:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.