SDKPython SDK

Runtime modes

Choose foreground, background, or manual update scheduling and stop the runtime correctly.

Current version · 1.4.0

Runtime modes

Automatic reconnection advances independently and does not require continuous application update() calls or a runner. The modes below only decide how other SDK scheduling work advances.

Foreground

exo.run_forever() occupies the current thread and suits command-line programs. Ctrl+C requests a stop.

Background

After start() succeeds, call exo.run_background() to start the background run.

join() waits for background completion and reports runtime errors. In an asyncio application, run one asyncio.to_thread(exo.join) task concurrently with data consumption. When the background run ends, cancel pending data waits and inspect the original join result. On consumption completion or cancellation, request stop if still running, await the same join task, then close Exo and Sdk. Keep cleanup in finally and protect its task against repeated cancellation; cancelling to_thread() does not stop the underlying join. Retain references to the SDK and join task until cleanup finishes.

If the data-reading task has already finished, inspect its result too; do not discard its completed exception as a cancellation result.

Manual updates

An existing loop can advance the SDK explicitly:

import time

from qnbot_sdk import SleepResult

while True:
    update = exo.update()
    sleep_result = update.sleep()
    if sleep_result is SleepResult.NO_TASKS:
        time.sleep(0.01)
    elif sleep_result is SleepResult.STOPPED:
        break

Call sleep() once after every update(). has_next_task only reports whether a periodic deadline exists; do not use it to gate sleep(), because event-driven work is not necessarily reflected by that field. NO_TASKS means the SDK currently has nothing to wait on, so yield briefly to avoid busy polling. Never run manual, foreground, and background drivers at the same time.

stop() stops the domain. Per-device start() and stop() are for independent multi-device control. Restarting the same Sdk keeps the physical port chosen at construction.

Independent multi-device lifecycle

first = exo.device("first")
second = exo.device("second")

first.start()
second.start()
second.stop()  # first remains started

Automatic recovery applies only to devices that were started before the connection was lost. A device that has been stopped does not start itself when the port returns; call start() again.

Closing the owning SDK or domain from other application logic ends the related data waits and coordinates with a pending background join. The application must still await its existing join observer and inspect the result. For ordinary shutdown, keep the stop, same join, then close order.

Temporary silence or connection recovery does not mean the background run has ended. Channel waits do not end merely because data is absent. Use the join result to observe background completion; a data-wait timeout is not a background completion result. Explicit stop()/start() follows the existing lifecycle: after stopping, wait for the previous background join to finish before restarting.

SDK update notices at startup

Exo checks OTA at the first Exo start per SDK instance. The check looks for a newer stable version for the current binding and platform and waits at most one second. It prints the available version and upgrade link to standard error. It does not install updates. There is no separate Core check. If OTA is unreachable, normal startup continues. See Installation & requirements to upgrade.