message
sleap.message
¶
Module with classes for sending and receiving messages between processes.
These use ZMQ pub/sub sockets.
Most of the time you'll want the PairedSender and PairedReceiver. These support a "handshake" to confirm connection. Without an initial handshake there's a good chance early messages will be dropped.
Each message is either dictionary or dictionary + numpy ndarray.
Classes:
| Name | Description |
|---|---|
BaseMessageParticipant |
Base class for simple Sender and Receiver. |
PairedReceiver |
|
PairedSender |
|
Receiver |
Receives messages from corresponding Sender. |
Sender |
Publishes messages to corresponding Receiver. |
BaseMessageParticipant
¶
Base class for simple Sender and Receiver.
Source code in sleap/message.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
PairedReceiver
¶
Bases: PairedMessageParticipant
Methods:
| Name | Description |
|---|---|
check_messages |
Checks for messages. |
receive_handshake |
Waits to receive and acknowledge handshake message. |
Source code in sleap/message.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
check_messages(ack_handshakes=True, *args, **kwargs)
¶
Checks for messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ack_handshakes
|
bool
|
If True, then any handshake messages are acknowledged and aren't included in return results |
True
|
Results
List of messages, possibly excluding any handshake requests.
Source code in sleap/message.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
receive_handshake(timeout_sec=30)
¶
Waits to receive and acknowledge handshake message.
Source code in sleap/message.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
PairedSender
¶
Bases: PairedMessageParticipant
Methods:
| Name | Description |
|---|---|
send_handshake |
Send handshake until we get reply. |
Source code in sleap/message.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
send_handshake(timeout_sec=30)
¶
Send handshake until we get reply.
Source code in sleap/message.py
185 186 187 188 189 190 191 192 193 194 195 196 197 | |
Receiver
¶
Bases: BaseMessageParticipant
Receives messages from corresponding Sender.
Methods:
| Name | Description |
|---|---|
check_message |
Attempt to receive a single message. |
check_messages |
Attempt to receive multiple messages. |
push_back_message |
Act like we didn't receive this message yet. |
Source code in sleap/message.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
check_message(timeout=10, fresh=False)
¶
Attempt to receive a single message.
Source code in sleap/message.py
75 76 77 78 79 80 81 82 83 84 85 86 | |
check_messages(timeout=10, times_to_check=10)
¶
Attempt to receive multiple messages.
This method allows us to keep up with the messages by getting multiple messages that have been sent since the last check. It keeps checking until limit is reached or we check without getting any messages back.
Source code in sleap/message.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
push_back_message(message)
¶
Act like we didn't receive this message yet.
Source code in sleap/message.py
58 59 60 | |
Sender
¶
Bases: BaseMessageParticipant
Publishes messages to corresponding Receiver.
Methods:
| Name | Description |
|---|---|
send_array |
Sends dictionary + numpy ndarray. |
send_dict |
Sends dictionary. |
Source code in sleap/message.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
send_array(header_data, A, flags=0, copy=True, track=False)
¶
Sends dictionary + numpy ndarray.
Source code in sleap/message.py
137 138 139 140 141 142 143 144 145 146 147 148 | |
send_dict(data)
¶
Sends dictionary.
Source code in sleap/message.py
131 132 133 134 135 | |