atexit invokes shutdown for you on
process exit), but they’re useful for tests, manual checkpoints, and
health-check endpoints.
All three are available both as module-level functions
(ci.flush(), ci.health(), ci.shutdown()) and as methods on a
Profiler handle.
flush
Synchronously drain the scope stack and mark buffer to the local
spool.
flush blocks the calling thread until the drain is complete. It
does not close the root scope; ci.profile() stays live and
continues to accept scopes and marks.
health
Snapshot of SDK internals. Never raises; safe to call from an HTTP
health check.
Drop counts that climb during a run are a signal to either raise the
buffer cap (
Cirron(spool_max_bytes=...)) or reduce the rate of
ci.mark calls.
spool_bytes reports what the cap is enforced against, which counts both
sealed *.json batches and unsealed *.json.tmp writes. spool_drop_count
covers evicted batch files only: sweeping an orphaned temp file never bumps
it, because a temp file is garbage no reader could have consumed rather than
data you lost.
shutdown
Close the root scope, flush synchronously, stop the flush thread,
and clear the default singleton. Idempotent; calling it twice is a
no-op.
atexit handler registered during
ci.profile(). Call it yourself when:
- You’re in a test that wants a clean state between cases.
- You’re hot-reloading a module that calls
ci.profile(). - You want to deterministically release the flush thread and its
file handles before a
fork().
Signal handlers
ci.profile() also registers SIGTERM and SIGINT handlers that call
shutdown() before the default handler runs, so traces are never
lost on a kill or Ctrl-C.
See also
ci.trace is the read-back companion to
flush: it returns the current session’s scope tree as text, dict,
JSON, or a DataFrame without leaving the process. It is also exposed
as Profiler.trace() and Cirron.trace().
Related
ci.profile
The entry point that starts the lifecycle these manage.
ci.trace
In-process read-back of the scope tree.
Profiler type
The handle exposing the same methods on an instance.