Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hpp-rbprm-corba
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Humanoid Path Planner
hpp-rbprm-corba
Commits
82d8ca0f
Commit
82d8ca0f
authored
4 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
[Python] ServerManager is now available in hpp-corbaserver
parent
3431a1e1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/hpp/corbaserver/rbprm/utils.py
+36
-30
36 additions, 30 deletions
src/hpp/corbaserver/rbprm/utils.py
with
36 additions
and
30 deletions
src/hpp/corbaserver/rbprm/utils.py
+
36
−
30
View file @
82d8ca0f
...
...
@@ -4,35 +4,41 @@
import
os
import
subprocess
import
time
import
warnings
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
()
from
hpp.utils
import
ServerManager
warnings
.
warn
(
'
Please import ServerManager directly from hpp.utils
'
,
DeprecationWarning
)
except
ImportError
:
# hpp-corbaserver < 4.9.1 fallback
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment