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

Merge pull request #74 from nim65s/devel

ServerManager: use version from hpp-corbaserver is available
parents 8f543eae 82d8ca0f
......@@ -4,27 +4,41 @@
import os
import subprocess
import time
import warnings
try:
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:
"""A context to ensure a server is running."""
def __init__(self, server):
self.server = server
subprocess.run(['killall', self.server])
def __enter__(self):
"""Run the server in background
stdout and stderr outputs of the child process are redirected to devnull (hidden).
preexec_fn is used to ignore ctrl-c signal send to the main script
(otherwise they are forwarded to the child process)
"""
self.process = subprocess.Popen(self.server,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
preexec_fn=os.setpgrp)
# give it some time to start
time.sleep(3)
def __exit__(self, exc_type, exc_value, exc_traceback):
self.process.kill()
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
run(['killall', self.server])
def __enter__(self):
"""Run the server in background
stdout and stderr outputs of the child process are redirected to devnull (hidden).
preexec_fn is used to ignore ctrl-c signal send to the main script
(otherwise they are forwarded to the child process)
"""
self.process = subprocess.Popen(self.server,
stdout=DEVNULL,
stderr=DEVNULL,
preexec_fn=os.setpgrp)
# give it some time to start
time.sleep(3)
def __exit__(self, exc_type, exc_value, exc_traceback):
self.process.kill()
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