2013-07-17 62 views
4

我運行在Amazon EC2上的Ubuntu 12.04的xvfb的服務器上執行以下PyQt的應用程序,我得到正確的輸出中從Qt應用程序,但是當應用程序完成後我總是得到上述錯誤。爲什麼我得到這個錯誤?我認爲這可能是因爲xvfb服務器沒有正確終止,但我不確定。的Xvfb IO錯誤:客戶端打死

import sys 
from PyQt4.QtGui import * 
from PyQt4.QtCore import * 
from PyQt4.QtWebKit import * 
from xvfbwrapper import Xvfb 


args = {"nolisten":"tcp"} 
vdisplay = Xvfb(**args) 
vdisplay.start() 
app = QApplication(sys.argv) 
def update(): 
    print "upd" 
t = QTimer() 
t.start(500) 
t.timeout.connect(update) 
stopTimer = QTimer(timeout=app.quit,singleShot=True) 
stopTimer.start(4000) 
app.exec_() 
print "done with app" 
vdisplay.stop() 

回答

3

對我來說@烏陵的解決方案不工作,因爲如果你不使用vdisplay.stop(),此XVFB過程是當腳本退出,這是一個問題殺害。我的解決方案是與後臺調用明確殺死進程,片刻後:

# Workaround for a problem preventing vdisplay.stop() to work 
# normally, because apparently Qt is still keeping its handle on X 
# at this point. 
import os 
os.system('(sleep 5 && kill -9 %d) &' % vdisplay.proc.pid) 
+0

睡了一個短終止後的時間也解析了直接使用xvfb-run運行時類似的錯誤消息(儘管我複製並修改了xvfb-run來這樣做) – Gnat

0

另一種醜陋的方式來解決,這是在其他子包的一切:

import xvfbwrapper 
import sys 
import subprocess as sub 

with xvfbwrapper.Xvfb(): 
    p = sub.Popen(
     ["python", "yourscript.py"] + sys.argv[1:], 
     stdout=sub.PIPE, stderr=sub.PIPE 
    ) 
    stdout, stderr = p.communicate() 
    print stdout 
    print >> sys.stderr, stderr 
    sys.exit(p.returncode)