在 python 中刷新 shell 子进程

refresh a shell subprocess in python

我有一个 webpy 代码,它使用子进程将 "ps aux" 数据发送到网页。

import subprocess
ps = subprocess.Popen(('ps', 'aux'), stdout-subprocess.PIPE)
out = ps.communicate()[0]

(bunch of webpy stuff)
class index:
    def GET(self):
        return (output)
(more webpy to start the web server)

它可以毫无问题地发送 ps 辅助数据,但是它不会刷新 ps 辅助数据,所以我只得到 1 个连续的数据集,而不是我需要的一组不断变化的数据。

如何在每次重新加载网页时刷新子进程以发送新数据?

Popen 调用放入 def GET。顺便说一句,如果你使用 Python 2.7 或更新版本,你可以使用 check_output 来简化实际的子进程调用:

def GET(self):
    return subprocess.check_output(['ps', 'aux'])