Xvfb IO Error: Client Killed

I run the following pyqt application on the xvfb server on amazon ec2 ubuntu 12.04, I get the correct output from the qt application, but always get the above error when the application is completed. Why am I getting this error? I think this may be due to the xvfb server not ending correctly, but I'm not sure.

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() 
+4
source share
2 answers

For me, @urim's solution does not work, because if you do not use vdisplay.stop() , the Xvfb process is not killed when the script exits, which is the problem. My solution is to explicitly close the process using a background call after a while:

 # 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) 
+3
source

Another ugly way around this is to wrap everything in another subprocess:

 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) 
0
source

Source: https://habr.com/ru/post/1491986/


All Articles