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

[Python 2] mock Python3 for ServerManager

parent 8f543eae
...@@ -5,12 +5,20 @@ import os ...@@ -5,12 +5,20 @@ import os
import subprocess import subprocess
import time 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: class ServerManager:
"""A context to ensure a server is running.""" """A context to ensure a server is running."""
def __init__(self, server): def __init__(self, server):
self.server = server self.server = server
subprocess.run(['killall', self.server]) run(['killall', self.server])
def __enter__(self): def __enter__(self):
"""Run the server in background """Run the server in background
...@@ -20,8 +28,8 @@ class ServerManager: ...@@ -20,8 +28,8 @@ class ServerManager:
(otherwise they are forwarded to the child process) (otherwise they are forwarded to the child process)
""" """
self.process = subprocess.Popen(self.server, self.process = subprocess.Popen(self.server,
stdout=subprocess.DEVNULL, stdout=DEVNULL,
stderr=subprocess.DEVNULL, stderr=DEVNULL,
preexec_fn=os.setpgrp) preexec_fn=os.setpgrp)
# give it some time to start # give it some time to start
time.sleep(3) 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