Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
force-bdss
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
Service Desk
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
Show more breadcrumbs
Adham Hashibon
force-bdss
Commits
15919e38
Commit
15919e38
authored
7 years ago
by
Stefano Borini
Browse files
Options
Downloads
Patches
Plain Diff
Handle reconnection
parent
8d3cf0b4
No related branches found
No related tags found
1 merge request
!79
Deliver notification info
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
force_bdss/core_plugins/dummy/ui_notification/ui_notification.py
+21
-7
21 additions, 7 deletions
...dss/core_plugins/dummy/ui_notification/ui_notification.py
utils/zmq_client.py
+13
-2
13 additions, 2 deletions
utils/zmq_client.py
with
34 additions
and
9 deletions
force_bdss/core_plugins/dummy/ui_notification/ui_notification.py
+
21
−
7
View file @
15919e38
from
traits.api
import
Any
from
traits.api
import
Any
,
List
from
force_bdss.api
import
BaseNotificationListener
from
force_bdss.api
import
BaseNotificationListener
import
zmq
import
zmq
class
UINotification
(
BaseNotificationListener
):
class
UINotification
(
BaseNotificationListener
):
_zmq_context
=
Any
()
_context
=
Any
()
_zmq_socket
=
Any
()
_pub_socket
=
Any
()
_rep_socket
=
Any
()
_msg_cache
=
List
()
def
deliver
(
self
,
model
,
message
):
def
deliver
(
self
,
model
,
message
):
self
.
_zmq_socket
.
send
((
"
ACTION {}
"
.
format
(
message
)).
encode
(
"
utf-8
"
))
try
:
data
=
self
.
_rep_socket
.
recv
(
flags
=
zmq
.
NOBLOCK
)
except
zmq
.
ZMQError
:
pass
else
:
self
.
_rep_socket
.
send_multipart
(
self
.
_msg_cache
)
msg
=
"
ACTION {}
"
.
format
(
message
).
encode
(
"
utf-8
"
)
self
.
_msg_cache
.
append
(
msg
)
self
.
_pub_socket
.
send
(
msg
)
def
init_persistent_state
(
self
,
model
):
def
init_persistent_state
(
self
,
model
):
self
.
_zmq_context
=
zmq
.
Context
()
self
.
_context
=
zmq
.
Context
()
self
.
_zmq_socket
=
self
.
_zmq_context
.
socket
(
zmq
.
PUB
)
self
.
_pub_socket
=
self
.
_context
.
socket
(
zmq
.
PUB
)
self
.
_zmq_socket
.
bind
(
"
tcp://*:12345
"
)
self
.
_pub_socket
.
bind
(
"
tcp://*:12345
"
)
self
.
_rep_socket
=
self
.
_context
.
socket
(
zmq
.
REP
)
self
.
_rep_socket
.
bind
(
"
tcp://*:12346
"
)
This diff is collapsed.
Click to expand it.
utils/zmq_client.py
+
13
−
2
View file @
15919e38
...
@@ -5,9 +5,20 @@ port = "5556"
...
@@ -5,9 +5,20 @@ port = "5556"
# Socket to talk to server
# Socket to talk to server
context
=
zmq
.
Context
()
context
=
zmq
.
Context
()
socket
=
context
.
socket
(
zmq
.
SUB
)
socket
=
context
.
socket
(
zmq
.
SUB
)
socket
.
connect
(
"
tcp://localhost:12345
"
)
socket
.
connect
(
"
tcp://localhost:12345
"
)
socket
.
setsockopt
(
zmq
.
SUBSCRIBE
,
""
.
encode
(
"
utf-8
"
))
socket
.
setsockopt
(
zmq
.
SUBSCRIBE
,
""
.
encode
(
"
utf-8
"
))
send_socket
=
context
.
socket
(
zmq
.
REQ
)
send_socket
.
connect
(
"
tcp://localhost:12346
"
)
send_socket
.
send
(
"
hello
"
.
encode
(
"
utf-8
"
))
while
True
:
try
:
data
=
send_socket
.
recv_multipart
(
flags
=
zmq
.
NOBLOCK
)
except
zmq
.
ZMQError
:
pass
else
:
print
(
"
RECOVERING CACHE
"
,
data
)
break
while
True
:
while
True
:
string
=
socket
.
recv
()
string
=
socket
.
recv
()
...
...
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