Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid hanging Xvfb processes [while using PyVirtualDisplay]?

Trying to find how to avoid hanging Xvfb processes in our Python application, when using PyVirtualDisplay. The essential problem is that calling display.stop() (see code sample below) does not seem to properly shut down the Xvfb process.

PyVirtualDisplay is very simply used:

from pyvirtualdisplay import Display

display = Display(backend='xvfb')
display.start()

... # Some stuff happens here

display.stop()

Now, the Display class has a slight modification to prevent Xvfb from using TCP ports: basically, add -nolisten tcp to the executing command. The modification is done by overriding the appropriate XfvbDisplay class's _cmd property:

@property
def _cmd(self):
    cmd = [PROGRAM,
           dict(black='-br', white='-wr')[self.bgcolor],
           '-screen',
           str(self.screen),
           'x'.join(map(str, list(self.size) + [self.color_depth])),
           self.new_display_var,
           '-nolisten',
           'tcp'
           ]
    return cmd

What is the proper way to end the Xvfb processes in this context so that they are terminated and do not linger?

Thanks very much!

like image 431
Juan Carlos Coto Avatar asked Aug 27 '13 22:08

Juan Carlos Coto


2 Answers

Your display, since it inherits from EasyProcess, will have a popen attribute at display.popen. You can use this to terminate, if EasyProcess isn't working properly.

So, you can do something like this:

display.popen.terminate()

or

display.popen.kill()
like image 182
Jordan Avatar answered Oct 04 '22 02:10

Jordan


The answer by Jordan did not work for me. This worked:

display.sendstop()
like image 29
birdnerd Avatar answered Oct 04 '22 03:10

birdnerd