Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Humanoid Path Planner
hpp-rbprm-corba
Commits
3431a1e1
Commit
3431a1e1
authored
Jun 08, 2020
by
Guilhem Saurel
Browse files
[Python 2] mock Python3 for ServerManager
parent
8f543eae
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/hpp/corbaserver/rbprm/utils.py
View file @
3431a1e1
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment