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
6cfa840c
Commit
6cfa840c
authored
Jul 01, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use weakrefs for the get_nodes function
parent
03d0dd98
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
4 deletions
+18
-4
src/netns/node.py
src/netns/node.py
+18
-4
No files found.
src/netns/node.py
View file @
6cfa840c
#!/usr/bin/env python
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
# vim:ts=4:sw=4:et:ai:sts=4
import
os
,
socket
,
sys
,
traceback
,
unshare
import
os
,
socket
,
sys
,
traceback
,
unshare
,
weakref
import
netns.protocol
import
netns.protocol
class
Node
(
object
):
class
Node
(
object
):
_nodes
=
[]
_nodes
=
weakref
.
WeakValueDictionary
()
_nextnode
=
0
@
classmethod
@
classmethod
def
get_nodes
(
cls
):
def
get_nodes
(
cls
):
return
set
(
cls
.
_nodes
)
s
=
sorted
(
Node
.
_nodes
.
items
(),
key
=
lambda
x
:
x
[
0
])
return
[
x
[
1
]
for
x
in
s
]
def
__init__
(
self
,
debug
=
False
):
def
__init__
(
self
,
debug
=
False
):
"""Create a new node in the emulation. Implemented as a separate
"""Create a new node in the emulation. Implemented as a separate
process in a new network name space. Requires root privileges to run.
process in a new network name space. Requires root privileges to run.
...
@@ -19,7 +22,18 @@ class Node(object):
...
@@ -19,7 +22,18 @@ class Node(object):
fd
,
pid
=
_start_child
(
debug
)
fd
,
pid
=
_start_child
(
debug
)
self
.
_pid
=
pid
self
.
_pid
=
pid
self
.
_slave
=
netns
.
protocol
.
Client
(
fd
,
debug
)
self
.
_slave
=
netns
.
protocol
.
Client
(
fd
,
debug
)
Node
.
_nodes
.
append
(
self
)
Node
.
_nodes
[
Node
.
_nextnode
]
=
self
Node
.
_nextnode
+=
1
def
__del__
(
self
):
print
"__del__(%s)"
%
self
self
.
shutdown
()
def
shutdown
(
self
):
self
.
_slave
.
shutdown
()
del
self
.
_pid
del
self
.
_slave
@
property
@
property
def
pid
(
self
):
def
pid
(
self
):
return
self
.
_pid
return
self
.
_pid
...
...
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