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)>”
pid = int(open(‘/tmp/.X99-lock’).read().strip())
print ‘lock file not found’
Again, it’s not elegant but it surely did the trick!