Skip to content

Commit c25577f

Browse files
authored
Use thread::park() in HangThread. (PyO3#5115)
* Use thread::park() in HangThread. std::thread::park() is basically Rust's version of libc::pause(), it waits for a 'signal' from std::thread::unpark(). On its own it can be used as a way to block forever without needing to resort to sleep(9999999) or platform-specific apis. * Add newsfragment.
1 parent c25c6f7 commit c25577f

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

newsfragments/5115.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use `std::thread::park()` instead of `libc::pause()` or `sleep(9999999)`.

pyo3-ffi/src/pystate.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,7 @@ struct HangThread;
8787
impl Drop for HangThread {
8888
fn drop(&mut self) {
8989
loop {
90-
#[cfg(target_family = "unix")]
91-
unsafe {
92-
libc::pause();
93-
}
94-
#[cfg(not(target_family = "unix"))]
95-
std::thread::sleep(std::time::Duration::from_secs(9_999_999));
90+
std::thread::park(); // Block forever.
9691
}
9792
}
9893
}

0 commit comments

Comments
 (0)