Skip to content

Commit 07560f7

Browse files
chore(rust): Disallow usage of tokio::spawn in clippy (#28123)
Co-authored-by: Ritchie Vink <[email protected]>
1 parent aa5d073 commit 07560f7

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

‎crates/clippy.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ disallowed-types = ["std::collections::HashMap", "std::collections::HashSet"]
22

33
disallowed-methods = [
44
{ path = "regex::Regex::new", reason = "use polars_utils::regex_cache" },
5+
{ path = "tokio::spawn", reason = "use ASYNC.spawn (polars_async::ASYNC)" },
56
]

‎crates/polars-io/src/cloud/cloud_writer/internal_writer.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::num::NonZeroUsize;
33
use futures::StreamExt as _;
44
use futures::stream::FuturesUnordered;
55
use object_store::PutPayload;
6+
use polars_core::runtime::ASYNC;
67
use polars_error::{PolarsError, PolarsResult};
78
use polars_utils::async_utils::error_capture::{ErrorCapture, ErrorHandle};
89
use polars_utils::async_utils::tokio_handle_ext;
@@ -112,9 +113,9 @@ impl InternalCloudWriter {
112113

113114
let fut = async move { io_metrics.record_bytes_tx(num_bytes, upload_fut).await };
114115

115-
let handle = tokio_handle_ext::AbortOnDropHandle(tokio::spawn(
116-
state.error_capture.clone().wrap_future(fut),
117-
));
116+
let handle = tokio_handle_ext::AbortOnDropHandle(
117+
ASYNC.spawn(state.error_capture.clone().wrap_future(fut)),
118+
);
118119

119120
state.tasks.push(handle);
120121

‎crates/polars-io/src/cloud/concurrency/mod.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::time::{Duration, Instant};
2626
pub use admission::{InFlightBudget, InFlightPermit, InFlightStats};
2727
use crossbeam_queue::ArrayQueue;
2828
pub use model::Model;
29+
use polars_core::runtime::ASYNC;
2930
use polars_utils::relaxed_cell::RelaxedCell;
3031
pub use regime::{Regime, RegimeState};
3132

@@ -203,7 +204,7 @@ impl ConcurrencyController {
203204
config.control_interval.as_millis()
204205
);
205206
}
206-
tokio::spawn(async move {
207+
ASYNC.spawn(async move {
207208
let mut model = Model::new(config.window);
208209
let mut regime = Regime::new(Instant::now());
209210

‎crates/polars-stream/src/nodes/io_sources/csv/line_batch_source.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl LineBatchSource {
8282

8383
let read_loop_handle =
8484
tokio_handle_ext::AbortOnDropHandle(ASYNC.spawn_blocking(move || {
85-
let handle = tokio::runtime::Handle::current();
8685
if verbose {
8786
eprintln!("[CsvSource]: Start line splitting async");
8887
}
@@ -100,7 +99,7 @@ impl LineBatchSource {
10099

101100
while let Some(batch) = producer.next_batch()? {
102101
// Effectively, this is `blocking_send`.
103-
if handle.block_on(line_batch_tx.send(batch)).is_err() {
102+
if ASYNC.block_on(line_batch_tx.send(batch)).is_err() {
104103
break;
105104
}
106105
}

‎crates/polars-stream/src/nodes/io_sources/ndjson/line_batch_distributor.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ impl LineBatchDistributor {
8080

8181
let read_loop_handle =
8282
tokio_handle_ext::AbortOnDropHandle(ASYNC.spawn_blocking(move || {
83-
let handle = tokio::runtime::Handle::current();
8483
if verbose {
8584
eprintln!("[NDJsonFileReader]: Start line batch distributor async");
8685
}
@@ -99,7 +98,7 @@ impl LineBatchDistributor {
9998

10099
while let Some(batch) = producer.next_batch()? {
101100
// Effectively, this is `blocking_send`.
102-
if handle.block_on(line_batch_tx.send(batch)).is_err() {
101+
if ASYNC.block_on(line_batch_tx.send(batch)).is_err() {
103102
break;
104103
}
105104
}

0 commit comments

Comments
 (0)