2015-06-27 60 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']) 
相關問題