fix: kill Xvfb with SIGKILL and clean up X11 lock/socket files

Replace the terminate→wait→kill fallback in VirtualDisplay.kill() with a
direct SIGKILL to prevent zombie Xvfb processes. After the process exits,
remove the stale /tmp/.X{n}-lock and /tmp/.X11-unix/X{n} files so future
display allocations are not blocked. Also set self.proc = None to mark the
display as fully cleaned up.
This commit is contained in:
Praveen Senpai
2026-06-22 20:55:48 +05:30
parent b1a96687c2
commit 71fe02899f
+13 -6
View File
@@ -1,4 +1,5 @@
import os
import signal
import select
import subprocess # nosec
import time
@@ -115,14 +116,20 @@ class VirtualDisplay:
if self.proc and self.proc.poll() is None:
if self.debug:
print("Terminating virtual display:", self._display)
self.proc.terminate()
try:
self.proc.send_signal(signal.SIGKILL)
self.proc.wait(timeout=5)
except subprocess.TimeoutExpired:
if self.debug:
print("Xvfb did not exit in time, killing forcefully")
self.proc.kill()
self.proc.wait()
except Exception:
pass
try:
os.remove(f"/tmp/.X{self._display}-lock")
except FileNotFoundError:
pass
try:
os.remove(f"/tmp/.X11-unix/X{self._display}")
except FileNotFoundError:
pass
self.proc = None
@staticmethod
def _assert_linux() -> None: