Commit 3431a1e1 authored by Guilhem Saurel's avatar Guilhem Saurel

[Python 2] mock Python3 for ServerManager

parent 8f543eae
......@@ -5,12 +5,20 @@ import os
import subprocess
import time
try:
from subprocess import DEVNULL, run
except ImportError: # Python2 fallback
DEVNULL = os.open(os.devnull, os.O_RDWR)
def run(*args):
subprocess.Popen(*args).wait()
class ServerManager:
"""A context to ensure a server is running."""
def __init__(self, server):
self.server = server
subprocess.run(['killall', self.server])
run(['killall', self.server])
def __enter__(self):
"""Run the server in background
......@@ -20,8 +28,8 @@ class ServerManager:
(otherwise they are forwarded to the child process)
"""
self.process = subprocess.Popen(self.server,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
stdout=DEVNULL,
stderr=DEVNULL,
preexec_fn=os.setpgrp)
# give it some time to start
time.sleep(3)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment