DIE XVFB, DIE!!

I had a bunch of “fun” with Ubuntu’s xvfb (x-windows virtual frame buffer) today.  Despite my best efforts, it would randomly choose to just hang around for no apparent reason. My Python script just sat around waiting for the subprocess to be released but to no avail.

My script was supposed to load a local HTML file in Firefox and get a screen capture using PageSaver Pro and then close the browser. In some instances however, the browser would quit but xvfb didn’t. Of course, this wasn’t an issue on my Mac because I didn’t need to run a virtual frame buffer as a display is connected to it.

After much futzing around and an inordinate amount of Google searching, I was finally able to figure out a less-than-elegant for fool-proof solution to the problem.

Here’s the Python code snippet:

from subprocess import call
import os, signal


cmd = “xvfb-run ‘<xvfb arguments>’ <program to execute (e.g. firefox)>”
call(cmd, shell=True)
try:
pid = int(open(‘/tmp/.X99-lock’).read().strip())
os.kill(pid, signal.SIGINT)
except:
print ‘lock file not found’

Again, it’s not elegant but it surely did the trick!

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: