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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
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 -*-
import
logging
import
Queue
import
socket
import
thread
import
time
...
...
@@ -87,12 +88,11 @@ class ResilientInstance(object):
self
.
halter_id
=
0
self
.
inElection
=
False
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
.
okCanal
=
self
.
comm
.
canal
([
MSG_OK
])
self
.
okCanal
=
self
.
comm
.
c
reate_c
anal
([
MSG_OK
])
self
.
confpath
=
confpath
self
.
loadConnectionInfo
()
...
...
@@ -185,29 +185,24 @@ class ResilientInstance(object):
return
True
class
FilteredCanal
(
object
):
def
__init__
(
self
,
accept
,
timeout
):
self
.
accept
=
accept
self
.
list
=
[]
self
.
lock
=
thread
.
allocate_lock
()
self
.
queue
=
Queue
.
Queue
()
self
.
timeout
=
timeout
def
append
(
self
,
message
,
sender
):
if
message
in
self
.
accept
:
self
.
lock
.
acquire
()
self
.
list
.
append
([
message
,
sender
])
self
.
lock
.
release
()
self
.
queue
.
put
([
message
,
sender
])
def
get
(
self
):
start
=
time
.
clock
()
while
(
time
.
clock
()
-
start
<
self
.
timeout
):
self
.
lock
.
acquire
()
if
self
.
list
:
self
.
lock
.
release
()
return
self
.
list
.
pop
(
0
)
self
.
lock
.
release
()
return
[
None
,
None
]
try
:
return
self
.
queue
.
get
(
timeout
=
self
.
timeout
)
except
Queue
.
Empty
:
return
[
None
,
None
]
class
Wrapper
(
object
):
...
...
@@ -243,7 +238,7 @@ class Wrapper(object):
finally
:
s
.
close
()
def
canal
(
self
,
accept
):
def
c
reate_c
anal
(
self
,
accept
):
created
=
FilteredCanal
(
accept
,
self
.
timeout
)
self
.
canals
.
append
(
created
)
return
created
...
...
@@ -286,11 +281,7 @@ def run(args):
computer
.
comm
.
start
()
thread
.
start_new_thread
(
computer
.
listen
,
())
thread
.
start_new_thread
(
computer
.
main
,
())
thread
.
start_new_thread
(
computer
.
aliveManagement
,
())
while
True
:
# XXX tight loop
continue
computer
.
main
()
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