This PR makes tokio initialization lazy, which allows for more idiomatic module imports and should make Python multiprocessing less problematic. Motivations for these changes can be found in #32
Changes:
pyo3_asyncio::tokio::init now accepts a tokio::runtime::Builder instead of a tokio::runtime::Runtime
This function no longer panics when called twice, only the most recent builder config is used
init does not actually build the runtime, it instead stores the config so the runtime can be built upon the first call to pyo3_asyncio::tokio::get_runtime
Tokio's current thread scheduler now requires the user to manually spawn the thread:
This makes current thread initialization more explicit, but it also allows more control over when and where the worker thread is spawned. Spawning it immediately may not be desirable for Python multiprocessing since the fork() system call only clones the thread that called it. For this reason it's preferable to spawn this thread only after the process has been forked, whereas the Builder initialization can occur before the fork if desired.
I think current-thread is not the primary use-case right now so it probably won't affect too many people.
Removed most tokio initialization functions to reduce the API surface. Users of multi-threaded scheduler just need to remove their initialization calls. Any other configuration is supported, but more verbose.
This PR might be bundled into #30 for a single disruptive initialization change.
This PR makes tokio initialization lazy, which allows for more idiomatic module imports and should make Python multiprocessing less problematic. Motivations for these changes can be found in #32
Changes:
pyo3_asyncio::tokio::init
now accepts atokio::runtime::Builder
instead of atokio::runtime::Runtime
pyo3_asyncio::tokio::get_runtime
Tokio's current thread scheduler now requires the user to manually spawn the thread:
fork()
system call only clones the thread that called it. For this reason it's preferable to spawn this thread only after the process has been forked, whereas theBuilder
initialization can occur before the fork if desired.This PR might be bundled into #30 for a single disruptive initialization change.