1
2
3
4
5
6
7
8
9
10
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
//! Process-wide tokio runtime, initialized lazily on first use.
//!
//! NEVER initialize at import/module-load time: spawning runtime threads
//! before an application forks (common in Python preload patterns) leaves
//! the child with a dead runtime. Lazy init means a child that never
//! touched the SDK pre-fork gets a fresh runtime on first use.
use Future;
use OnceLock;
use Runtime;
static RUNTIME: = new;
/// Return the process-wide multi-threaded tokio runtime, building it on first
/// call. Safe to call after a fork in a child that never used the SDK pre-fork.
/// Drive a future to completion on the shared runtime, the sync facade for
/// callers outside any async context (the PyO3 bridge with the GIL released,
/// and the CLI).
///
/// `block_on` panics if called from within a tokio runtime ("Cannot start a
/// runtime from within a runtime"). Our sync entry points are never inside one,
/// so this is a debug-only guard documenting that invariant; an async Rust host
/// embedding the core should call the `async` API directly instead.