From dc8d6e8e8ac6e6be2607f94d6df4b62431ed3480 Mon Sep 17 00:00:00 2001 From: Moritz Schlarb Date: Thu, 26 Sep 2013 14:24:46 +0200 Subject: [PATCH] Make Xvfb a contextmanager --- xvfbwrapper/xvfbwrapper.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xvfbwrapper/xvfbwrapper.py b/xvfbwrapper/xvfbwrapper.py index 92825cd..2562d87 100644 --- a/xvfbwrapper/xvfbwrapper.py +++ b/xvfbwrapper/xvfbwrapper.py @@ -37,6 +37,13 @@ class Xvfb: else: self.old_display_num = 0 + def __enter__(self): + self.start() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self.stop() + def start(self): self.vdisplay_num = self.search_for_free_display() self.xvfb_cmd = ['Xvfb', ':%d' % self.vdisplay_num] + self.xvfb_cmd