This commit is contained in:
Erik Johnston
2026-07-28 11:09:45 +01:00
parent 41cbc96b26
commit a4ed2ca2b8
7 changed files with 37 additions and 25 deletions
+3 -1
View File
@@ -44,7 +44,9 @@ impl HomeServer {
.0
.bind(py)
.call_method0(intern!(py, "get_rust_runtime"))?
.extract()?)
.cast::<RustRuntime>()?
.get()
.clone())
}
/// The Rust-side view of `hs.config`.
+5 -2
View File
@@ -50,7 +50,7 @@ impl HttpClient {
#[new]
#[pyo3(signature = (runtime, user_agent, http2_only = false))]
pub fn py_new(
runtime: RustRuntime,
runtime: &RustRuntime,
user_agent: &str,
http2_only: bool,
) -> PyResult<HttpClient> {
@@ -64,7 +64,10 @@ impl HttpClient {
let client = builder.build().context("building reqwest client")?;
Ok(HttpClient { client, runtime })
Ok(HttpClient {
client,
runtime: runtime.clone(),
})
}
pub fn get<'a>(
+11 -3
View File
@@ -128,7 +128,7 @@ impl Drop for RustRuntimeInner {
/// constructor argument — pyo3 extracts a `#[pyclass]` that is `Clone` by
/// cloning, which here is just an `Arc` refcount bump — and hold their own
/// clone. Derefs to [`RustRuntimeInner`].
#[pyclass(frozen, from_py_object, module = "synapse.synapse_rust")]
#[pyclass(frozen, skip_from_py_object)]
#[derive(Clone)]
pub struct RustRuntime {
inner: Arc<RustRuntimeInner>,
@@ -191,8 +191,16 @@ impl ShutdownHook {
}
/// Called when registering modules with python.
pub fn register_module(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<RustRuntime>()?;
pub fn register_module(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
let child_module = PyModule::new(py, "runtime")?;
child_module.add_class::<RustRuntime>()?;
m.add_submodule(&child_module)?;
py.import("sys")?
.getattr("modules")?
.set_item("synapse.synapse_rust.runtime", child_module)?;
Ok(())
}
+1 -1
View File
@@ -174,10 +174,10 @@ from synapse.state import StateHandler, StateResolutionHandler
from synapse.storage import Databases
from synapse.storage.controllers import StorageControllers
from synapse.streams.events import EventSources
from synapse.synapse_rust import RustRuntime
from synapse.synapse_rust.handlers import RustHandlers
from synapse.synapse_rust.msc4388_rendezvous import MSC4388RendezvousHandler
from synapse.synapse_rust.rendezvous import RendezvousHandler
from synapse.synapse_rust.runtime import RustRuntime
from synapse.types import DomainSpecificString, ISynapseReactor
from synapse.util import SYNAPSE_VERSION
from synapse.util.caches import CACHE_METRIC_REGISTRY
-17
View File
@@ -1,21 +1,4 @@
from synapse.types import ISynapseReactor
def sum_as_string(a: int, b: int) -> str: ...
def get_rust_file_digest() -> str: ...
def reset_logging_config() -> None: ...
def get_rustc_version() -> str: ...
class RustRuntime:
"""The per-homeserver state for the Rust side of Synapse.
Holds the tokio thread pool (started lazily on first use, shut down by a
reactor shutdown trigger) and a handle to the reactor. Rust classes that
need either take this as a constructor argument; get it from
`hs.get_rust_runtime()`.
"""
def __init__(
self,
reactor: ISynapseReactor,
worker_threads: int = 4,
) -> None: ...
+1 -1
View File
@@ -14,7 +14,7 @@ from typing import Mapping
from twisted.internet.defer import Deferred
from synapse.synapse_rust import RustRuntime
from synapse.synapse_rust.runtime import RustRuntime
class HttpClient:
"""
+16
View File
@@ -0,0 +1,16 @@
from synapse.types import ISynapseReactor
class RustRuntime:
"""The per-homeserver state for the Rust side of Synapse.
Holds the tokio thread pool (started lazily on first use, shut down by a
reactor shutdown trigger) and a handle to the reactor. Rust classes that
need either take this as a constructor argument; get it from
`hs.get_rust_runtime()`.
"""
def __init__(
self,
reactor: ISynapseReactor,
worker_threads: int = 4,
) -> None: ...