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