Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Klaus Wölfel
slapos
Commits
d44ce5f5
Commit
d44ce5f5
authored
Nov 19, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid busy loops, use threadsafe Queue
parent
224c7d98
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
22 deletions
+13
-22
slapos/recipe/addresiliency/bully.py
slapos/recipe/addresiliency/bully.py
+13
-22
No files found.
slapos/recipe/addresiliency/bully.py
View file @
d44ce5f5
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
logging
import
logging
import
Queue
import
socket
import
socket
import
thread
import
thread
import
time
import
time
...
@@ -87,12 +88,11 @@ class ResilientInstance(object):
...
@@ -87,12 +88,11 @@ class ResilientInstance(object):
self
.
halter_id
=
0
self
.
halter_id
=
0
self
.
inElection
=
False
self
.
inElection
=
False
self
.
alive
=
True
self
.
alive
=
True
self
.
lastPing
=
time
.
clock
()
self
.
mainCanal
=
self
.
comm
.
canal
([
MSG_PING
,
MSG_HALT
,
MSG_VICTORY
])
self
.
mainCanal
=
self
.
comm
.
c
reate_c
anal
([
MSG_PING
,
MSG_HALT
,
MSG_VICTORY
])
self
.
renamer
=
renamer
self
.
renamer
=
renamer
self
.
okCanal
=
self
.
comm
.
canal
([
MSG_OK
])
self
.
okCanal
=
self
.
comm
.
c
reate_c
anal
([
MSG_OK
])
self
.
confpath
=
confpath
self
.
confpath
=
confpath
self
.
loadConnectionInfo
()
self
.
loadConnectionInfo
()
...
@@ -185,29 +185,24 @@ class ResilientInstance(object):
...
@@ -185,29 +185,24 @@ class ResilientInstance(object):
return
True
return
True
class
FilteredCanal
(
object
):
class
FilteredCanal
(
object
):
def
__init__
(
self
,
accept
,
timeout
):
def
__init__
(
self
,
accept
,
timeout
):
self
.
accept
=
accept
self
.
accept
=
accept
self
.
list
=
[]
self
.
queue
=
Queue
.
Queue
()
self
.
lock
=
thread
.
allocate_lock
()
self
.
timeout
=
timeout
self
.
timeout
=
timeout
def
append
(
self
,
message
,
sender
):
def
append
(
self
,
message
,
sender
):
if
message
in
self
.
accept
:
if
message
in
self
.
accept
:
self
.
lock
.
acquire
()
self
.
queue
.
put
([
message
,
sender
])
self
.
list
.
append
([
message
,
sender
])
self
.
lock
.
release
()
def
get
(
self
):
def
get
(
self
):
start
=
time
.
clock
()
try
:
while
(
time
.
clock
()
-
start
<
self
.
timeout
):
return
self
.
queue
.
get
(
timeout
=
self
.
timeout
)
self
.
lock
.
acquire
()
except
Queue
.
Empty
:
if
self
.
list
:
return
[
None
,
None
]
self
.
lock
.
release
()
return
self
.
list
.
pop
(
0
)
self
.
lock
.
release
()
return
[
None
,
None
]
class
Wrapper
(
object
):
class
Wrapper
(
object
):
...
@@ -243,7 +238,7 @@ class Wrapper(object):
...
@@ -243,7 +238,7 @@ class Wrapper(object):
finally
:
finally
:
s
.
close
()
s
.
close
()
def
canal
(
self
,
accept
):
def
c
reate_c
anal
(
self
,
accept
):
created
=
FilteredCanal
(
accept
,
self
.
timeout
)
created
=
FilteredCanal
(
accept
,
self
.
timeout
)
self
.
canals
.
append
(
created
)
self
.
canals
.
append
(
created
)
return
created
return
created
...
@@ -286,11 +281,7 @@ def run(args):
...
@@ -286,11 +281,7 @@ def run(args):
computer
.
comm
.
start
()
computer
.
comm
.
start
()
thread
.
start_new_thread
(
computer
.
listen
,
())
thread
.
start_new_thread
(
computer
.
listen
,
())
thread
.
start_new_thread
(
computer
.
main
,
())
thread
.
start_new_thread
(
computer
.
aliveManagement
,
())
thread
.
start_new_thread
(
computer
.
aliveManagement
,
())
while
True
:
computer
.
main
()
# XXX tight loop
continue
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