diff --git a/src/marker.rs b/src/marker.rs index 2fcaf613dae..93a11691755 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -318,7 +318,7 @@ impl<'py> Python<'py> { use std::mem::transmute; use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe}; use std::sync::mpsc::{sync_channel, SendError, SyncSender}; - use std::thread::{spawn, Result}; + use std::thread::{Builder, Result}; use std::time::Duration; use parking_lot::{const_mutex, Mutex}; @@ -344,11 +344,15 @@ impl<'py> Python<'py> { let mut f = Some(f); let mut task = || { - let f = f.take().unwrap(); + let f = f + .take() + .expect("allow_threads closure called more than once"); let result = catch_unwind(AssertUnwindSafe(f)); - result_sender.send(result).unwrap(); + result_sender + .send(result) + .expect("allow_threads runtime task was abandoned"); }; // SAFETY: the current thread will block until the closure has returned @@ -371,22 +375,27 @@ impl<'py> Python<'py> { let (task_sender, task_receiver) = sync_channel::(0); - spawn(move || { - let mut next_task = Ok(task); + Builder::new() + .name("pyo3 allow_threads runtime".to_owned()) + .spawn(move || { + let mut next_task = Ok(task); - while let Ok(task) = next_task { - // SAFETY: all data accessed by `task` will stay alive until it completes - unsafe { (*task.0)() }; + while let Ok(task) = next_task { + // SAFETY: all data accessed by `task` will stay alive until it completes + unsafe { (*task.0)() }; - next_task = task_receiver.recv_timeout(Duration::from_secs(60)); - } - }); + next_task = task_receiver.recv_timeout(Duration::from_secs(60)); + } + }) + .expect("failed to create allow_threads runtime thread"); task_sender }; // 3. Wait for completion and check result - let result = result_receiver.recv().unwrap(); + let result = result_receiver + .recv() + .expect("allow_threads runtime thread died unexpectedly"); trap.disarm();