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
e7d6ad6c
Unverified
Commit
e7d6ad6c
authored
Jun 09, 2020
by
Guilhem Saurel
Committed by
GitHub
Jun 09, 2020
Browse files
Merge pull request #74 from nim65s/devel
ServerManager: use version from hpp-corbaserver is available
parents
8f543eae
82d8ca0f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/hpp/corbaserver/rbprm/utils.py
View file @
e7d6ad6c
...
...
@@ -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
()
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