Skip to content

Commit

Permalink
Most naive solution to the problem:
Browse files Browse the repository at this point in the history
make CloudWriter call `get_runtime().block_on` from a newly spawned thread.
  • Loading branch information
Qqwy committed Feb 4, 2024
1 parent fccfe4e commit e03a835
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions crates/polars-io/src/cloud/adaptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,16 @@ impl CloudWriter {

impl std::io::Write for CloudWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
get_runtime().block_on(async {
let res = self.writer.write(buf).await;
if res.is_err() {
let _ = self.abort().await;
}
res
std::thread::scope(|s| {
s.spawn(|| {
get_runtime().block_on(async {
let res = self.writer.write(buf).await;
if res.is_err() {
let _ = self.abort().await;
}
res
})
}).join().unwrap()
})
}

Expand All @@ -219,7 +223,11 @@ impl std::io::Write for CloudWriter {

impl Drop for CloudWriter {
fn drop(&mut self) {
let _ = get_runtime().block_on(self.writer.shutdown());
std::thread::scope(|s| {
s.spawn(|| {
let _ = get_runtime().block_on(self.writer.shutdown());
}).join().unwrap()
})
}
}

Expand Down

0 comments on commit e03a835

Please sign in to comment.