diff --git a/Cargo.lock b/Cargo.lock index 851382b98ba1..134c857a11a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1420,7 +1420,6 @@ dependencies = [ "re_crash_handler", "re_sdk_comms", "re_viewer", - "tokio", ] [[package]] @@ -1973,7 +1972,6 @@ dependencies = [ "re_crash_handler", "re_sdk_comms", "re_viewer", - "tokio", ] [[package]] @@ -3096,7 +3094,6 @@ name = "minimal_serve" version = "0.16.0-alpha.1+dev" dependencies = [ "rerun", - "tokio", ] [[package]] @@ -4686,7 +4683,6 @@ dependencies = [ "re_log_types", "re_smart_channel", "thiserror", - "tokio", ] [[package]] @@ -5318,7 +5314,6 @@ dependencies = [ "re_viewer", "re_web_viewer_server", "re_ws_comms", - "tokio", ] [[package]] @@ -5333,7 +5328,6 @@ dependencies = [ "re_log", "re_memory", "rerun", - "tokio", ] [[package]] @@ -5380,7 +5374,6 @@ dependencies = [ "re_sdk", "re_web_viewer_server", "re_ws_comms", - "tokio", "uuid", ] @@ -6388,35 +6381,6 @@ dependencies = [ "ahash", ] -[[package]] -name = "tokio" -version = "1.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105" -dependencies = [ - "autocfg", - "bytes", - "libc", - "mio", - "num_cpus", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.48.0", -] - -[[package]] -name = "tokio-macros" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "toml" version = "0.8.10" diff --git a/Cargo.toml b/Cargo.toml index 3bcc4b8babc6..e51070f75557 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -219,7 +219,6 @@ tiny_http = { version = "0.12", default-features = false } tinystl = { version = "0.0.3", default-features = false } tinyvec = { version = "1.6", features = ["alloc", "rustc_1_55"] } tobj = "4.0" -tokio = { version = "1.24", default-features = false } toml = { version = "0.8.10", default-features = false } tracing = { version = "0.1", default-features = false } tungstenite = { version = "0.20", default-features = false } diff --git a/crates/re_sdk/src/recording_stream.rs b/crates/re_sdk/src/recording_stream.rs index f37053686baf..c0affed8233f 100644 --- a/crates/re_sdk/src/recording_stream.rs +++ b/crates/re_sdk/src/recording_stream.rs @@ -461,9 +461,6 @@ impl RecordingStreamBuilder { /// Creates a new [`RecordingStream`] that is pre-configured to stream the data through to a /// web-based Rerun viewer via WebSockets. /// - /// This method needs to be called in a context where a Tokio runtime is already running (see - /// example below). - /// /// If the `open_browser` argument is `true`, your default browser will be opened with a /// connected web-viewer. /// @@ -481,16 +478,6 @@ impl RecordingStreamBuilder { /// ## Example /// /// ```ignore - /// // Ensure we have a running tokio runtime. - /// let mut tokio_runtime = None; - /// let tokio_runtime_handle = if let Ok(handle) = tokio::runtime::Handle::try_current() { - /// handle - /// } else { - /// let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime"); - /// tokio_runtime.get_or_insert(rt).handle().clone() - /// }; - /// let _tokio_runtime_guard = tokio_runtime_handle.enter(); - /// /// let rec = re_sdk::RecordingStreamBuilder::new("rerun_example_app") /// .serve("0.0.0.0", /// Default::default(), diff --git a/crates/re_sdk/src/web_viewer.rs b/crates/re_sdk/src/web_viewer.rs index cb9e2123a407..d6d32053df62 100644 --- a/crates/re_sdk/src/web_viewer.rs +++ b/crates/re_sdk/src/web_viewer.rs @@ -122,8 +122,6 @@ impl crate::sink::LogSink for WebViewerSink { /// NOTE: you can not connect one `Session` to another. /// /// This function returns immediately. -/// -/// The caller needs to ensure that there is a `tokio` runtime running. #[must_use = "the sink must be kept around to keep the servers running"] pub fn new_sink( open_browser: bool, diff --git a/crates/re_sdk_comms/Cargo.toml b/crates/re_sdk_comms/Cargo.toml index 341a67d42564..9ce91ab96dca 100644 --- a/crates/re_sdk_comms/Cargo.toml +++ b/crates/re_sdk_comms/Cargo.toml @@ -24,7 +24,7 @@ all-features = true client = ["re_log_encoding/encoder"] ## Enable the server. -server = ["rand", "tokio", "re_log_encoding/decoder"] +server = ["rand", "re_log_encoding/decoder"] [dependencies] @@ -46,9 +46,3 @@ rand = { workspace = true, optional = true, features = [ "std_rng", "small_rng", ] } - -tokio = { workspace = true, optional = true, features = [ - "io-util", - "net", - "rt", -] } diff --git a/crates/re_sdk_comms/src/server.rs b/crates/re_sdk_comms/src/server.rs index 3ad74cbbe93b..346b20939251 100644 --- a/crates/re_sdk_comms/src/server.rs +++ b/crates/re_sdk_comms/src/server.rs @@ -1,7 +1,10 @@ -use std::{io::ErrorKind, time::Instant}; +use std::{ + io::{ErrorKind, Read as _}, + net::{TcpListener, TcpStream}, + time::Instant, +}; use rand::{Rng as _, SeedableRng}; -use tokio::net::{TcpListener, TcpStream}; use re_log_types::{LogMsg, TimePoint, TimeType, TimelineName}; use re_smart_channel::{Receiver, Sender}; @@ -13,6 +16,9 @@ pub enum ServerError { bind_addr: String, err: std::io::Error, }, + + #[error(transparent)] + FailedToSpawnThread(#[from] std::io::Error), } #[derive(thiserror::Error, Debug)] @@ -68,12 +74,15 @@ impl Default for ServerOptions { /// /// ``` no_run /// # use re_sdk_comms::{serve, ServerOptions}; -/// #[tokio::main] -/// async fn main() { -/// let log_msg_rx = serve("0.0.0.0", re_sdk_comms::DEFAULT_SERVER_PORT, ServerOptions::default()).await.unwrap(); +/// fn main() { +/// let log_msg_rx = serve("0.0.0.0", re_sdk_comms::DEFAULT_SERVER_PORT, ServerOptions::default()).unwrap(); /// } /// ``` -pub async fn serve( +/// +/// Internally spawns a thread that listens for incoming TCP connections on the given `bind_ip` and `port` +/// and one thread per connected client. +// TODO(andreas): Reconsider if we should use `smol` tasks instead of threads both here and in re_ws_comms. +pub fn serve( bind_ip: &str, port: u16, options: ServerOptions, @@ -85,13 +94,16 @@ pub async fn serve( ); let bind_addr = format!("{bind_ip}:{port}"); - let listener = - TcpListener::bind(&bind_addr) - .await - .map_err(|err| ServerError::TcpBindError { - bind_addr: bind_addr.clone(), - err, - })?; + let listener = TcpListener::bind(&bind_addr).map_err(|err| ServerError::TcpBindError { + bind_addr: bind_addr.clone(), + err, + })?; + + std::thread::Builder::new() + .name("rerun_sdk_comms: listener".to_owned()) + .spawn(move || { + listen_for_new_clients(&listener, options, &tx); + })?; if options.quiet { re_log::debug!( @@ -103,19 +115,24 @@ pub async fn serve( ); } - tokio::spawn(listen_for_new_clients(listener, options, tx)); - Ok(rx) } -async fn listen_for_new_clients(listener: TcpListener, options: ServerOptions, tx: Sender) { - #[allow(clippy::infinite_loop)] // TODO(emilk): some way of aborting this loop +fn listen_for_new_clients(listener: &TcpListener, options: ServerOptions, tx: &Sender) { + // TODO(emilk): some way of aborting this loop + #[allow(clippy::infinite_loop)] loop { - match listener.accept().await { + match listener.accept() { Ok((stream, _)) => { let addr = stream.peer_addr().ok(); let tx = tx.clone_as(re_smart_channel::SmartMessageSource::TcpClient { addr }); - spawn_client(stream, tx, options, addr); + + std::thread::Builder::new() + .name("rerun_sdk_comms: client".to_owned()) + .spawn(move || { + spawn_client(stream, &tx, options, addr); + }) + .ok(); } Err(err) => { re_log::warn!("Failed to accept incoming SDK client: {err}"); @@ -126,46 +143,41 @@ async fn listen_for_new_clients(listener: TcpListener, options: ServerOptions, t fn spawn_client( stream: TcpStream, - tx: Sender, + tx: &Sender, options: ServerOptions, peer_addr: Option, ) { - tokio::spawn(async move { - let addr_string = - peer_addr.map_or_else(|| "(unknown ip)".to_owned(), |addr| addr.to_string()); + let addr_string = peer_addr.map_or_else(|| "(unknown ip)".to_owned(), |addr| addr.to_string()); - if options.quiet { - re_log::debug!("New SDK client connected: {addr_string}"); - } else { - re_log::info!("New SDK client connected: {addr_string}"); - } + if options.quiet { + re_log::debug!("New SDK client connected: {addr_string}"); + } else { + re_log::info!("New SDK client connected: {addr_string}"); + } - if let Err(err) = run_client(stream, &tx, options).await { - if let ConnectionError::SendError(err) = &err { - if err.kind() == ErrorKind::UnexpectedEof { - // Client gracefully severed the connection. - tx.quit(None).ok(); // best-effort at this point - return; - } + if let Err(err) = run_client(stream, tx, options) { + if let ConnectionError::SendError(err) = &err { + if err.kind() == ErrorKind::UnexpectedEof { + // Client gracefully severed the connection. + tx.quit(None).ok(); // best-effort at this point + return; } - re_log::warn_once!("Closing connection to client at {addr_string}: {err}"); - let err: Box = err.to_string().into(); - tx.quit(Some(err)).ok(); // best-effort at this point } - }); + re_log::warn_once!("Closing connection to client at {addr_string}: {err}"); + let err: Box = err.to_string().into(); + tx.quit(Some(err)).ok(); // best-effort at this point + } } -async fn run_client( +fn run_client( mut stream: TcpStream, tx: &Sender, options: ServerOptions, ) -> Result<(), ConnectionError> { #![allow(clippy::read_zero_byte_vec)] // false positive: https://github.com/rust-lang/rust-clippy/issues/9274 - use tokio::io::AsyncReadExt as _; - let mut client_version = [0_u8; 2]; - stream.read_exact(&mut client_version).await?; + stream.read_exact(&mut client_version)?; let client_version = u16::from_le_bytes(client_version); match client_version.cmp(&crate::PROTOCOL_VERSION) { @@ -190,11 +202,11 @@ async fn run_client( loop { let mut packet_size = [0_u8; 4]; - stream.read_exact(&mut packet_size).await?; + stream.read_exact(&mut packet_size)?; let packet_size = u32::from_le_bytes(packet_size); packet.resize(packet_size as usize, 0_u8); - stream.read_exact(&mut packet).await?; + stream.read_exact(&mut packet)?; re_log::trace!("Received packet of size {packet_size}."); diff --git a/crates/re_web_viewer_server/src/lib.rs b/crates/re_web_viewer_server/src/lib.rs index dc88f9e79385..853be4d107a1 100644 --- a/crates/re_web_viewer_server/src/lib.rs +++ b/crates/re_web_viewer_server/src/lib.rs @@ -37,10 +37,6 @@ pub enum WebViewerServerError { #[error("Failed to create server at address {0}: {1}")] CreateServerFailed(String, Box), - - #[cfg(feature = "sync")] - #[error("Failed to spawn web viewer thread: {0}")] - ThreadSpawnFailed(#[from] std::io::Error), } // ---------------------------------------------------------------------------- diff --git a/crates/rerun-cli/Cargo.toml b/crates/rerun-cli/Cargo.toml index a6e1effcf0e8..501ad7ce2a6f 100644 --- a/crates/rerun-cli/Cargo.toml +++ b/crates/rerun-cli/Cargo.toml @@ -67,7 +67,6 @@ rerun = { workspace = true, features = [ document-features.workspace = true mimalloc.workspace = true -tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } [build-dependencies] diff --git a/crates/rerun-cli/src/bin/rerun.rs b/crates/rerun-cli/src/bin/rerun.rs index ad6b3c223703..bc8a6ffd0a92 100644 --- a/crates/rerun-cli/src/bin/rerun.rs +++ b/crates/rerun-cli/src/bin/rerun.rs @@ -16,13 +16,12 @@ use re_memory::AccountingAllocator; static GLOBAL: AccountingAllocator = AccountingAllocator::new(mimalloc::MiMalloc); -#[tokio::main] -async fn main() -> std::process::ExitCode { +fn main() -> std::process::ExitCode { re_log::setup_logging(); let build_info = re_build_info::build_info!(); - let result = rerun::run(build_info, rerun::CallSource::Cli, std::env::args()).await; + let result = rerun::run(build_info, rerun::CallSource::Cli, std::env::args()); match result { Ok(exit_code) => std::process::ExitCode::from(exit_code), diff --git a/crates/rerun/Cargo.toml b/crates/rerun/Cargo.toml index 09751a1bdac2..03ee3a3c5646 100644 --- a/crates/rerun/Cargo.toml +++ b/crates/rerun/Cargo.toml @@ -43,7 +43,7 @@ analytics = [ ] ## Integration with `clap`. -clap = ["dep:clap", "dep:tokio"] +clap = ["dep:clap"] ## Support for using Rerun's data-loaders directly from the SDK. ## @@ -84,7 +84,6 @@ run = [ "dep:re_log_encoding", "dep:re_sdk_comms", "dep:re_ws_comms", - "dep:tokio", ] ## Support for running a TCP server that listens to incoming log messages from a Rerun SDK. @@ -143,12 +142,6 @@ rayon.workspace = true # Native, optional: clap = { workspace = true, optional = true, features = ["derive"] } -tokio = { workspace = true, optional = true, features = [ - "macros", - "rt-multi-thread", - "time", -] } - [build-dependencies] re_build_tools.workspace = true diff --git a/crates/rerun/src/clap.rs b/crates/rerun/src/clap.rs index db7f1cafc1e1..61c2db5f379b 100644 --- a/crates/rerun/src/clap.rs +++ b/crates/rerun/src/clap.rs @@ -87,16 +87,15 @@ pub struct RerunArgs { #[doc(hidden)] #[derive(Default)] pub struct ServeGuard { - tokio_rt: Option, + block_on_drop: bool, } impl Drop for ServeGuard { fn drop(&mut self) { - if let Some(tokio_rt) = self.tokio_rt.take() { + if self.block_on_drop { eprintln!("Sleeping indefinitely while serving web viewer... Press ^C when done."); - tokio_rt.block_on(async { - tokio::time::sleep(std::time::Duration::from_secs(u64::MAX)).await; - }); + // TODO(andreas): It would be a lot better if we had a handle to the web server and could call `block_until_shutdown` on it. + std::thread::sleep(std::time::Duration::from_secs(u64::MAX)); } } } @@ -129,27 +128,9 @@ impl RerunArgs { #[cfg(feature = "web_viewer")] RerunBehavior::Serve => { - let mut tokio_rt = None; - - // Get the Tokio runtime for the current thread, or create one if there isn't any. - // If we do create one, we'll have to make sure it both outlives and gets - // polled to completion as we return from this method! - let tokio_rt_handle = if let Ok(handle) = tokio::runtime::Handle::try_current() { - handle - } else { - tokio_rt - .get_or_insert(tokio::runtime::Runtime::new()?) - .handle() - .clone() - }; - let server_memory_limit = re_memory::MemoryLimit::parse(&self.server_memory_limit) .map_err(|err| anyhow::format_err!("Bad --server-memory-limit: {err}"))?; - // Creating the actual web sink and associated servers will require the current - // thread to be in a Tokio context. - let _tokio_rt_guard = tokio_rt_handle.enter(); - let open_browser = true; let rec = RecordingStreamBuilder::new(application_id).serve( &self.bind, @@ -159,9 +140,10 @@ impl RerunArgs { open_browser, )?; - // If we had to create a Tokio runtime from scratch, make sure it outlives this - // method and gets polled to completion. - let sleep_guard = ServeGuard { tokio_rt }; + // Ensure the server stays alive until the end of the program. + let sleep_guard = ServeGuard { + block_on_drop: true, + }; Ok((rec, sleep_guard)) } diff --git a/crates/rerun/src/lib.rs b/crates/rerun/src/lib.rs index 698cb6cb5e4e..9553cb851e85 100644 --- a/crates/rerun/src/lib.rs +++ b/crates/rerun/src/lib.rs @@ -166,10 +166,6 @@ pub mod external { #[cfg(not(target_arch = "wasm32"))] pub use clap; - #[cfg(feature = "run")] - #[cfg(not(target_arch = "wasm32"))] - pub use tokio; - #[cfg(feature = "native_viewer")] pub use re_viewer; diff --git a/crates/rerun/src/run.rs b/crates/rerun/src/run.rs index bad95de20add..b2055c7bafca 100644 --- a/crates/rerun/src/run.rs +++ b/crates/rerun/src/run.rs @@ -331,7 +331,7 @@ impl CallSource { // // It would be nice to use [`std::process::ExitCode`] here but // then there's no good way to get back at the exit code from python -pub async fn run( +pub fn run( build_info: re_build_info::BuildInfo, call_source: CallSource, args: I, @@ -382,7 +382,7 @@ where Command::Reset => re_viewer::reset_viewer_persistence(), } } else { - run_impl(build_info, call_source, args).await + run_impl(build_info, call_source, args) }; match res { @@ -594,7 +594,7 @@ fn profiler(args: &Args) -> re_tracing::Profiler { profiler } -async fn run_impl( +fn run_impl( _build_info: re_build_info::BuildInfo, call_source: CallSource, args: Args, @@ -636,7 +636,7 @@ async fn run_impl( max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()), quiet: false, }; - let rx = re_sdk_comms::serve(&args.bind, args.port, server_options).await?; + let rx = re_sdk_comms::serve(&args.bind, args.port, server_options)?; vec![rx] } @@ -714,13 +714,12 @@ async fn run_impl( .map_err(|err| anyhow::format_err!("Bad --server-memory-limit: {err}"))?; // This is the server which the web viewer will talk to: - let ws_server = re_ws_comms::RerunServer::new( + let _ws_server = re_ws_comms::RerunServer::new( ReceiveSet::new(rx), &args.bind, args.ws_server_port, server_memory_limit, )?; - let _ws_server_url = ws_server.server_url(); #[cfg(feature = "web_viewer")] { @@ -735,7 +734,7 @@ async fn run_impl( args.web_viewer_port, args.renderer, open_browser, - &_ws_server_url, + &_ws_server.server_url(), )? .block(); // dropping should stop the server } diff --git a/examples/rust/custom_data_loader/src/main.rs b/examples/rust/custom_data_loader/src/main.rs index 761c9185a028..022745e1b971 100644 --- a/examples/rust/custom_data_loader/src/main.rs +++ b/examples/rust/custom_data_loader/src/main.rs @@ -7,20 +7,18 @@ //! ``` use rerun::{ - external::{anyhow, re_build_info, re_data_source, re_log, tokio}, + external::{anyhow, re_build_info, re_data_source, re_log}, log::{DataRow, RowId}, EntityPath, TimePoint, }; -#[tokio::main] -async fn main() -> anyhow::Result { +fn main() -> anyhow::Result { re_log::setup_logging(); re_data_source::register_custom_data_loader(HashLoader); let build_info = re_build_info::build_info!(); rerun::run(build_info, rerun::CallSource::Cli, std::env::args()) - .await .map(std::process::ExitCode::from) } diff --git a/examples/rust/custom_space_view/Cargo.toml b/examples/rust/custom_space_view/Cargo.toml index 952646cfa948..e80164e63f77 100644 --- a/examples/rust/custom_space_view/Cargo.toml +++ b/examples/rust/custom_space_view/Cargo.toml @@ -21,6 +21,3 @@ re_sdk_comms = { path = "../../../crates/re_sdk_comms", features = ["server"] } # mimalloc is a much faster allocator: mimalloc = "0.1" - -# We need tokio for re_sdk_comms: -tokio = { version = "1.24", features = ["macros", "rt-multi-thread"] } diff --git a/examples/rust/custom_space_view/src/main.rs b/examples/rust/custom_space_view/src/main.rs index 32d151b6c106..0fcc9159a907 100644 --- a/examples/rust/custom_space_view/src/main.rs +++ b/examples/rust/custom_space_view/src/main.rs @@ -12,8 +12,7 @@ mod color_coordinates_visualizer_system; static GLOBAL: re_memory::AccountingAllocator = re_memory::AccountingAllocator::new(mimalloc::MiMalloc); -#[tokio::main] -async fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { // Direct calls using the `log` crate to stderr. Control with `RUST_LOG=debug` etc. re_log::setup_logging(); @@ -27,8 +26,7 @@ async fn main() -> Result<(), Box> { "0.0.0.0", re_sdk_comms::DEFAULT_SERVER_PORT, Default::default(), - ) - .await?; + )?; let startup_options = re_viewer::StartupOptions::default(); diff --git a/examples/rust/custom_store_subscriber/src/main.rs b/examples/rust/custom_store_subscriber/src/main.rs index ed9b8c03e706..fd24e90b5425 100644 --- a/examples/rust/custom_store_subscriber/src/main.rs +++ b/examples/rust/custom_store_subscriber/src/main.rs @@ -13,13 +13,12 @@ use std::collections::BTreeMap; use rerun::{ - external::{anyhow, re_build_info, re_data_store, re_log, re_log_types::TimeRange, tokio}, + external::{anyhow, re_build_info, re_data_store, re_log, re_log_types::TimeRange}, time::TimeInt, ComponentName, EntityPath, StoreEvent, StoreId, StoreSubscriber, Timeline, }; -#[tokio::main] -async fn main() -> anyhow::Result { +fn main() -> anyhow::Result { re_log::setup_logging(); let _handle = re_data_store::DataStore::register_subscriber(Box::::default()); @@ -27,7 +26,6 @@ async fn main() -> anyhow::Result { let build_info = re_build_info::build_info!(); rerun::run(build_info, rerun::CallSource::Cli, std::env::args()) - .await .map(std::process::ExitCode::from) } diff --git a/examples/rust/extend_viewer_ui/Cargo.toml b/examples/rust/extend_viewer_ui/Cargo.toml index 78f480231f97..8f470162da51 100644 --- a/examples/rust/extend_viewer_ui/Cargo.toml +++ b/examples/rust/extend_viewer_ui/Cargo.toml @@ -21,6 +21,3 @@ re_sdk_comms = { path = "../../../crates/re_sdk_comms", features = ["server"] } # mimalloc is a much faster allocator: mimalloc = "0.1" - -# We need tokio for re_sdk_comms: -tokio = { version = "1.24", features = ["macros", "rt-multi-thread"] } diff --git a/examples/rust/extend_viewer_ui/src/main.rs b/examples/rust/extend_viewer_ui/src/main.rs index fbc37dee872b..f7cb1533392e 100644 --- a/examples/rust/extend_viewer_ui/src/main.rs +++ b/examples/rust/extend_viewer_ui/src/main.rs @@ -11,8 +11,7 @@ use re_viewer::external::{ static GLOBAL: re_memory::AccountingAllocator = re_memory::AccountingAllocator::new(mimalloc::MiMalloc); -#[tokio::main] -async fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { // Direct calls using the `log` crate to stderr. Control with `RUST_LOG=debug` etc. re_log::setup_logging(); @@ -26,8 +25,7 @@ async fn main() -> Result<(), Box> { "0.0.0.0", re_sdk_comms::DEFAULT_SERVER_PORT, Default::default(), - ) - .await?; + )?; let native_options = eframe::NativeOptions { viewport: egui::ViewportBuilder::default().with_app_id("rerun_extend_viewer_ui_example"), diff --git a/examples/rust/minimal_serve/Cargo.toml b/examples/rust/minimal_serve/Cargo.toml index 44db28b8491c..2e46275d5b95 100644 --- a/examples/rust/minimal_serve/Cargo.toml +++ b/examples/rust/minimal_serve/Cargo.toml @@ -8,4 +8,3 @@ publish = false [dependencies] rerun = { path = "../../../crates/rerun", features = ["web_viewer"] } -tokio = { version = "1.24", features = ["rt-multi-thread"] } diff --git a/examples/rust/minimal_serve/src/main.rs b/examples/rust/minimal_serve/src/main.rs index 81fa05aa0768..6cddaf9b3587 100644 --- a/examples/rust/minimal_serve/src/main.rs +++ b/examples/rust/minimal_serve/src/main.rs @@ -3,10 +3,6 @@ use rerun::{demo_util::grid, external::glam}; fn main() -> Result<(), Box> { - // `serve()` requires to have a running Tokio runtime in the current context. - let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime"); - let _guard = rt.enter(); - let open_browser = true; let rec = rerun::RecordingStreamBuilder::new("rerun_example_minimal_serve").serve( "0.0.0.0", diff --git a/rerun_py/Cargo.toml b/rerun_py/Cargo.toml index fe1f03b3bd8c..57b287160fa9 100644 --- a/rerun_py/Cargo.toml +++ b/rerun_py/Cargo.toml @@ -58,7 +58,6 @@ once_cell.workspace = true parking_lot.workspace = true pyo3 = { workspace = true, features = ["abi3-py38"] } rand = { workspace = true, features = ["std_rng"] } -tokio = { workspace = true, features = ["rt-multi-thread", "signal"] } uuid.workspace = true diff --git a/rerun_py/src/python_bridge.rs b/rerun_py/src/python_bridge.rs index ea753026bd00..2d67d968835e 100644 --- a/rerun_py/src/python_bridge.rs +++ b/rerun_py/src/python_bridge.rs @@ -794,14 +794,6 @@ impl PyMemorySinkStorage { } } -#[cfg(feature = "web_viewer")] -#[must_use = "the tokio_runtime guard must be kept alive while using tokio"] -fn enter_tokio_runtime() -> tokio::runtime::EnterGuard<'static> { - static TOKIO_RUNTIME: Lazy = - Lazy::new(|| tokio::runtime::Runtime::new().expect("Failed to create tokio runtime")); - TOKIO_RUNTIME.enter() -} - /// Serve a web-viewer. #[allow(clippy::unnecessary_wraps)] // False positive #[pyfunction] @@ -828,8 +820,6 @@ fn serve( let server_memory_limit = re_memory::MemoryLimit::parse(&server_memory_limit) .map_err(|err| PyRuntimeError::new_err(format!("Bad server_memory_limit: {err}:")))?; - let _guard = enter_tokio_runtime(); - let sink = re_sdk::web_viewer::new_sink( open_browser, "0.0.0.0", @@ -1122,7 +1112,6 @@ fn start_web_viewer_server(port: u16) -> PyResult<()> { { let mut web_handle = global_web_viewer_server(); - let _guard = enter_tokio_runtime(); *web_handle = Some( re_web_viewer_server::WebViewerServer::new("0.0.0.0", WebViewerServerPort(port)) .map_err(|err| {