Tools
CuemsDeploy: async rsync-based media and project deployer for CUEMS nodes.
Async model: _sync(), _check_mandatory_sources(), _kill(), and _pump() are coroutines scheduled on the event loop injected via NodeEngine.start() late-bind. sync_files() remains a synchronous blocking API; it submits _deploy_all_async() via run_coroutine_threadsafe() and blocks until completion. Watchdogs inside the coroutine bound all wait times.
Late-bind protocol
NodeEngine.init() creates CuemsDeploy(loop=None). NodeEngine.start() calls CUE_HANDLER.set_nng_comms(...), which starts AsyncCommsThread (creates the event_loop), then: self.deploy_manager.loop = CUE_HANDLER.communications_thread.event_loop Any sync_files() before that bind returns False immediately.
Why _avahi_resolve stays synchronous: it is called from init() before any asyncio loop exists, so subprocess.run() (short timeout) is correct.
CuemsDeploy
Source code in src/cuemsengine/tools/CuemsDeploy.py
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 116 117 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 209 210 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 264 265 266 267 268 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 297 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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 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 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
__init__(library_path='/opt/cuems_library/', tmp_path='/tmp/cuems_library/', controller_ip=None, hostname=None, log_file='/run/cuems/rsync.log', on_progress=None, loop=None, is_async=False)
Construct a deploy manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
controller_ip
|
str | None
|
IP of the controller's rsync daemon (preferred). Pass BaseEngine.controller_ip. If falsy, manager runs disabled. |
None
|
hostname
|
str | None
|
Legacy fallback resolved via avahi when controller_ip is not provided. Kept for backwards compatibility. |
None
|
log_file
|
str
|
Where rsync writes its log. |
'/run/cuems/rsync.log'
|
on_progress
|
Callable[[dict], None] | None
|
Optional callback fired for each rsync progress update (parsed from --info=progress2). Receives a dict with keys bytes, pct, rate, eta, and optionally xfr, remaining, total. Must be non-blocking — invoked from the asyncio loop. |
None
|
loop
|
AbstractEventLoop | None
|
The asyncio event loop for run_coroutine_threadsafe(). |
None
|
Source code in src/cuemsengine/tools/CuemsDeploy.py
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 | |
sync_files(project, tag, file_names=None)
Sync files from the controller to the node.
Dispatches to _sync_files_async (event-loop path) or _sync_files_blocking (subprocess path) based on self._is_async.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
str
|
Project identifier used to build paths and log file names. |
required |
tag
|
str
|
Transfer type — |
required |
file_names
|
list[str] | None
|
Explicit list of rsync-relative paths to transfer. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True on success; False on any failure. self.errors populated on failure. |
Source code in src/cuemsengine/tools/CuemsDeploy.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
MtcListener
Bases: Thread
Source code in src/cuemsengine/tools/MtcListener.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 116 117 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 209 210 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 264 265 266 267 268 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 297 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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
is_receiving(max_age_s=0.5)
True if an MTC message arrived within the last max_age_s seconds.
A listener that failed to open its port (or whose sender stopped) keeps a main_tc that looks like a valid reading -- 0.0 if it never received anything. ControllerEngine.go_script ships that reading as every node's GO anchor, so it must be able to tell a live reading from a dead one (test2, 2026-09-25, 869f79ecc). While MTC rolls, quarter frames arrive every ~10ms at 25fps, so 0.5s is generous.
Source code in src/cuemsengine/tools/MtcListener.py
184 185 186 187 188 189 190 191 192 193 194 195 | |
milliseconds()
Deprecated alias of milliseconds_rounded (CTimecode.milliseconds is deprecated).
Source code in src/cuemsengine/tools/MtcListener.py
177 178 179 180 181 182 | |
milliseconds_exact()
Float milliseconds from the current MTC.
Source code in src/cuemsengine/tools/MtcListener.py
173 174 175 | |
milliseconds_rounded()
Integer milliseconds from the current MTC.
Source code in src/cuemsengine/tools/MtcListener.py
169 170 171 | |
reset_24h_state()
Clear the 24h-wrap accumulator (control-plane reset).
Called from the engine's project-load/reset orchestration (NOT off the wire): a graceful reload sends MTC back toward 0 with only a SMALL backward delta, which the wire-driven reset in _apply_24h_offset cannot catch (it requires delta < -1h). Without this, a project loaded after a
24h run would start at hour 24+ and the cue-sequence reset_callback (gated on milliseconds_rounded == 0) would stay silenced forever.
Zeroes both the offset and the last-position memory (None sentinel, mirroring the C++ resetWrapOffset() → lastWireMs_ = -1) under the same lock the decode path uses, so it cannot interleave with a concurrent wrap accumulation on the callback thread.
Source code in src/cuemsengine/tools/MtcListener.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
PortHandler
Bases: object
Source code in src/cuemsengine/tools/PortHandler.py
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 116 117 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 209 210 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 264 265 266 267 268 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 297 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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 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 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
__new__()
Singleton class responsible for handling port objects.
Ports come in three kinds, and they are NOT interchangeable:
- Reservations —
_all_used_ports(per cue),_random_ports(OSC clients) and_pending(drawn, not yet registered). These are ports this handler handed out. Double-booking one is a real error and may raise. - Declarations —
_config_ports. Named service/config ports out of settings.xml. A declaration is a statement of fact, not a request to allocate, so registering one must never raise: two names may legitimately share a port, and a declared port may already be bound. - Observations —
_system_ports. Whatsscurrently sees bound on the host. Also never raises.
All three are excluded from allocation; only reservations are validated by check_ports(). Conflating them is what made NodeEngine.init crash in every earlier attempt at this fix (869ed9wf7).
Thread-safe: internal state mutations are guarded by an RLock.
Source code in src/cuemsengine/tools/PortHandler.py
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 | |
add_config_ports(ports)
Merge named config/service ports into the config scope.
NEVER raises. A config port is a declaration ("this port belongs to
that service"), not a request to allocate. Two names may legitimately
map to one port — stock settings.xml has osc_in_port_base 7000 and
the videocomposer default is also 7000 — and a declared port may
already be bound, as oscquery_ws_port 9190 is on a controller while
the node engine starts. Neither is an error; both used to crash
NodeEngine.init once check_ports()'s guards were reachable.
Source code in src/cuemsengine/tools/PortHandler.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
add_system_ports()
Snapshot every port currently bound on this host (observation only).
Source code in src/cuemsengine/tools/PortHandler.py
312 313 314 315 316 317 318 319 | |
assign_ports(names, cue=None)
Assign free ports to a list of names
This method is thread-safe and should be the preferred way to assign ports to a list of names for a cue or config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
list[str]
|
The names to assign ports to |
required |
cue
|
CuemsDict
|
The cue to assign ports to |
None
|
Source code in src/cuemsengine/tools/PortHandler.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
check_port_range(ports)
staticmethod
Check the port range
Source code in src/cuemsengine/tools/PortHandler.py
232 233 234 235 236 237 238 239 240 241 | |
check_ports(ports, check_range=True)
Check the ports for a cue and return the list of ports if they are valid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ports
|
list | dict
|
The ports to check |
required |
check_range
|
bool
|
Whether to check the port range |
True
|
Returns:
| Type | Description |
|---|---|
list
|
The ports list if they are valid |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/cuemsengine/tools/PortHandler.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
clean_random_ports()
Clean the random ports set by keeping only ports that are in use by the system, and refresh the system snapshot with the scan it already pays for.
Note this only started doing real work once get_used_ports() could see
other users' sockets: the old scan returned almost nothing, so this
wiped _random_ports wholesale on every project load. It now keeps
genuinely-bound ports, and still self-heals — a port whose client died
and released the socket drops out on the next load.
Source code in src/cuemsengine/tools/PortHandler.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
find_system_ports()
Find all ports currently bound on the system
Source code in src/cuemsengine/tools/PortHandler.py
306 307 308 309 310 | |
get_all_used_ports()
Every port the allocator must avoid: reservations, config declarations and observed system sockets.
Source code in src/cuemsengine/tools/PortHandler.py
191 192 193 194 195 196 197 198 199 200 | |
get_free_port()
Draw a free port and reserve it.
The returned port is added to _pending, so a concurrent draw cannot
return it too. It leaves _pending when set_ports(),
add_config_ports() or store_random_port() registers it properly, or
when release_pending()/clean_random_ports() gives it back.
Candidates are bind-probed before being handed out — the startup snapshot alone cannot see anything that bound after it was taken.
Returns:
| Type | Description |
|---|---|
int
|
The free port |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no free port could be found and verified. Never |
returns an unverified port
|
handing one out is exactly the bug |
Source code in src/cuemsengine/tools/PortHandler.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
get_free_ports(n)
Get n free ports, in draw order.
Distinct by construction: each draw reserves into _pending before
returning, so the next one cannot pick it again.
Source code in src/cuemsengine/tools/PortHandler.py
290 291 292 293 294 295 296 297 | |
get_ports(cue)
Get the ports for a cue
Source code in src/cuemsengine/tools/PortHandler.py
105 106 107 108 109 110 | |
new_random_port()
Get a new random port and store it
Source code in src/cuemsengine/tools/PortHandler.py
344 345 346 347 348 349 350 | |
release_pending(port)
Give back a port drawn by get_free_port() that will not be registered.
Source code in src/cuemsengine/tools/PortHandler.py
299 300 301 302 303 304 | |
remove_ports(cue)
Remove the ports for a cue
Source code in src/cuemsengine/tools/PortHandler.py
167 168 169 170 171 172 173 174 175 | |
remove_random_port(port)
Remove a specific port from the random ports list, freeing it for reuse. Called when an OSC client that owned the port is closed.
Source code in src/cuemsengine/tools/PortHandler.py
360 361 362 363 364 365 366 367 368 369 370 | |
set_ports(cue, ports, check_range=True)
Set the ports for a cue, replacing any it previously held.
Cue scope only — config ports go through add_config_ports(), which cannot raise.
Source code in src/cuemsengine/tools/PortHandler.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
store_random_port(port)
Store a random port to the random ports set
Source code in src/cuemsengine/tools/PortHandler.py
352 353 354 355 356 357 358 | |
port_is_bindable(port)
True if nothing currently holds port on either TCP or UDP.
Deliberately does NOT set SO_REUSEADDR: a socket lingering in TIME_WAIT
should count as taken. IPv4 only — the whole CUEMS stack (avahi, the
Inherently advisory: the probe releases the port before the real consumer binds it. It shrinks the race window from "permanently blind" to microseconds, which is the same bargain tests/helpers.py::free_udp_port already makes.
Source code in src/cuemsengine/tools/PortHandler.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
Reader for /run/cuems/display.conf.
display.conf is written by cuems-generate-display-conf (ExecStartPre of
cuems-videocomposer.service) and read by both the videocomposer (for DRM
modeset + canvas layout) and the engine (for canvas geometry + per-output
canvas regions, replacing the broken x = index * 1920 heuristic that used
to live in NodeEngine.set_video_outputs).
File format is INI-like:
canvas_layout=custom
canvas_size=5760x1080 # optional, overrides bbox
[output:HDMI-A-1]
canvas_region=0,0,1920,1080
resolution=1920x1080 # optional
refresh=60.0 # optional
enabled=false # optional; leaves the output dark
The engine consumes canvas_region, enabled and the optional global
canvas_size override; resolution + refresh are read by the videocomposer
directly.
An output with enabled set to anything but true/1 gets no surface and
stays out of the videocomposer's canvas even when it keeps a canvas_region, so
the engine leaves it out too (869fgq3xv). Otherwise the engine would route
cues to a dark output and compute a wider canvas than the videocomposer's,
placing every layer wrong.
DisplayConfNotFoundError
Bases: RuntimeError
display.conf is missing, unreadable, or has no [output:*] sections.
Source code in src/cuemsengine/tools/display_conf.py
43 44 | |
DisplayConfValueError
Bases: RuntimeError
display.conf is present but contains an invalid value (e.g. a canvas_size override that is malformed, non-positive, or smaller than the per-output region bounding box).
Source code in src/cuemsengine/tools/display_conf.py
47 48 49 50 | |
read_display_conf(path=DEFAULT_DISPLAY_CONF)
Parse display.conf and return (regions, canvas_size).
Returns a 2-tuple:
regions:{connector_name: {'x', 'y', 'width', 'height'}}with pixel-int values.canvas_size:(canvas_width, canvas_height). If the globalcanvas_size=WIDTHxHEIGHTkey is present in the file's preamble, it is used (after validating it is >= the per-region bounding box). Otherwise, computed asmax(x + width, y + height)over all regions.
Raises:
DisplayConfNotFoundErrorif the file is missing or has no enabled[output:*]section with a valid canvas_region.DisplayConfValueErrorifcanvas_size=is malformed, has non-positive values, or is smaller than the per-region bbox.
Source code in src/cuemsengine/tools/display_conf.py
113 114 115 116 117 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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 | |
get_used_ports()
Recover every local port currently bound on this host, TCP and UDP.
Uses ss -tuln — deliberately without -p. The owning PID is of no use
to the port allocator, and asking for it is actively harmful: ss hides
the whole users:(...) field for sockets owned by another user, and the
previous implementation only recorded a port when it could also read a
pid= out of that field. As a non-owner it therefore returned nothing at
all rather than a partial list, leaving the allocator blind to every
socket it did not own (869ed9wf7).
Returns:
| Type | Description |
|---|---|
set[int]
|
set[int]: Local ports currently bound. Empty if |
set[int]
|
that degrades the allocator to its previous behaviour rather than |
set[int]
|
taking the engine down. |
Source code in src/cuemsengine/tools/system_ports.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
is_port_in_use(port)
Check if a specific port is currently bound on this host.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int
|
The port number to check |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if port is in use, False otherwise |
Example
if is_port_in_use(8080): ... print("Port 8080 is in use")
Source code in src/cuemsengine/tools/system_ports.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |