Unverified Commit e7d6ad6c authored by Guilhem Saurel's avatar Guilhem Saurel Committed by GitHub
Browse files

Merge pull request #74 from nim65s/devel

ServerManager: use version from hpp-corbaserver is available
parents 8f543eae 82d8ca0f
...@@ -4,13 +4,27 @@ ...@@ -4,13 +4,27 @@
import os import os
import subprocess import subprocess
import time import time
import warnings
from hpp.utils import ServerManager
warnings.warn('Please import ServerManager directly from hpp.utils', DeprecationWarning)
except ImportError: # hpp-corbaserver < 4.9.1 fallback
class ServerManager: try:
from subprocess import DEVNULL, run
except ImportError: # Python2 fallback
DEVNULL = os.open(os.devnull, os.O_RDWR)
def run(*args):
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 +34,8 @@ class ServerManager: ...@@ -20,8 +34,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)
Supports Markdown
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