Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
d0d3ea07
Commit
d0d3ea07
authored
Jul 19, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Killing procs on destroy
parent
0c2fe63b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
6 deletions
+19
-6
src/netns/node.py
src/netns/node.py
+2
-2
src/netns/subprocess_.py
src/netns/subprocess_.py
+17
-4
No files found.
src/netns/node.py
View file @
d0d3ea07
...
...
@@ -27,9 +27,9 @@ class Node(object):
Node
.
_nextnode
+=
1
def
__del__
(
self
):
self
.
shutdown
()
self
.
destroy
()
def
shutdown
(
self
):
def
destroy
(
self
):
for
p
in
self
.
_processes
.
values
():
p
.
destroy
()
del
self
.
_processes
...
...
src/netns/subprocess_.py
View file @
d0d3ea07
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import
fcntl
,
grp
,
os
,
pickle
,
pwd
,
signal
,
select
,
sys
,
traceback
import
fcntl
,
grp
,
os
,
pickle
,
pwd
,
signal
,
select
,
sys
,
t
ime
,
t
raceback
__all__
=
[
'PIPE'
,
'STDOUT'
,
'Popen'
,
'Subprocess'
,
'spawn'
,
'wait'
,
'poll'
,
'system'
,
'backticks'
,
'backticks_raise'
]
# User-facing interfaces
KILL_WAIT
=
3
# seconds
class
Subprocess
(
object
):
"""Class that allows the execution of programs inside a netns Node. This is
the base class for all process operations, Popen provides a more high level
...
...
@@ -101,10 +103,21 @@ class Subprocess(object):
return
os
.
WEXITSTATUS
(
self
.
_returncode
)
raise
RuntimeError
(
"Invalid return code"
)
# pragma: no cover
# FIXME: do we have any other way to deal with this than having explicit
# destroy?
def
__del__
(
self
):
self
.
destroy
()
def
destroy
(
self
):
pass
if
self
.
_returncode
!=
None
:
return
self
.
signal
()
now
=
time
.
time
()
while
time
.
time
()
-
now
<
KILL_WAIT
:
if
self
.
poll
():
return
time
.
sleep
(
0.1
)
sys
.
stderr
.
write
(
"WARNING: killing forcefully process %d.
\
n
"
%
self
.
_pid
)
self
.
signal
(
signal
.
KILL
)
self
.
wait
()
PIPE
=
-
1
STDOUT
=
-
2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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