2015-06-27 83 views
0

我有一个webpy代码,它使用子进程将“ps aux”数据发送到网页。在Python中刷新shell子进程

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 AUX数据通过没有问题但它不刷新的ps aux数据,所以我只拿到1组连续的,而不是数据的集合改变我很需要。

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

+1

,你将不得不再次调用该函数 –

+0

你可以[使用'psutil'得到进程信息](https://pypi.python.org/pypi/psutil)。另请参阅[如何浏览服务器和浏览器浏览器工作](https://github.com/nicolargo/glances)。 – jfs

回答

2

Popen呼叫转入def GET。顺便说一句,如果你正在使用Python 2.7或更高版本,可以使用check_output简化实际子电话:

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