Link¤
Link
¤
Link(
*,
client: Client,
curve: AuthCurve | None,
host: str,
plain: AuthPlain | None,
service_name: str,
xpub_port: int
)
A link with a Service.
Source code in src/msl/network/client.py
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 | |
flag_at
instance-attribute
¤
flag_at: Callable[[Flag], AbstractContextManager[None]]
Reference to flag_at.
timeout
instance-attribute
¤
timeout: float | None
float | None — The number of seconds to wait for a reply from a synchronous request.
The value is initially None for new links, which means that there is no limit on the wait time.
__getattr__
¤
__getattr__(attr: str) -> FutureOrResult
All undefined attributes are sent to the linked Service to process.
The internal wrapper function that is returned is essentially:
def wrapper(*args: Any, sync: bool = True, **kwargs: Any) -> Any | Future[Any]:
future = request(self.service_name, attr, *args, **kwargs)
if sync:
return future.result(self.timeout)
return future
return wrapper
Warning
Your Service subclass cannot have method/attribute names that are the same as those found in the Link class, otherwise a request will not be sent to your Service because the Link instance will handle the method call.
Source code in src/msl/network/client.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
signatures
¤
Get the function signatures that the linked Service provides.
For example,
{
"get_resolution": "() -> tuple[int, int]",
"set_resolution": "(width: int, height: int) -> None",
"stream": "() -> None",
"version": "() -> str"
}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
The maximum number of seconds to wait for the reply.
If |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
A mapping between the function (attribute) name and the function signature (attribute type). |
Source code in src/msl/network/client.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
subscribe
¤
Subscribe to publications from the linked Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[Any], None]
|
A callback function to receive the published result. The callback receives a single argument, the published result, and the returned value is ignored. |
required |
Source code in src/msl/network/client.py
325 326 327 328 329 330 331 332 333 334 335 336 337 | |
timeout_at
¤
Use as a context manager to temporarily change the timeout value.
Example
from msl.network import Client
with Client() as c:
camera = c.link("Camera")
camera.timeout = 5 # (1)!
# uses a timeout of 5 seconds
resolution = camera.get_resolution()
with camera.timeout_at(None): # (2)!
# no timeout
images = camera.capture(n=100)
# uses a timeout of 5 seconds
shutter_speed = camera.get_shutter_speed()
- Use a timeout value of 5 seconds for each synchronous request.
- Temporarily disable the timeout to capture 100 images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
The temporary timeout value to use for synchronous requests while within the context. Once the context exits, the value is reset to the original value. |
required |
Source code in src/msl/network/client.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
unlink
¤
unlink() -> None
Unlink from the Service.
Source code in src/msl/network/client.py
376 377 378 379 380 381 382 383 | |
unsubscribe
¤
unsubscribe() -> None
Unsubscribe from receiving publications from the linked Service.
Source code in src/msl/network/client.py
385 386 387 388 389 | |