Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PyO3 to 0.23 #200

Merged
merged 2 commits into from
Feb 14, 2025
Merged

Update PyO3 to 0.23 #200

merged 2 commits into from
Feb 14, 2025

Conversation

ngoldbaum
Copy link
Contributor

Opening as a draft to see how CI feels about this change and because lock().unwrap() may swallow panics incorrectly.

@lgray
Copy link

lgray commented Feb 9, 2025

@ngoldbaum I'm really interested in helping get this out, we use cramjam in our data analysis stack and I'd like to finally be able to use multithreading as opposed to multiprocessing. Is there any way I can help?

The current error seems a bit mysterious, but I'll take a crack at reproducing.

@lgray
Copy link

lgray commented Feb 9, 2025

Hmm, that test passed on my laptop (osx-arm64), so either flaky test or os-dependent?

@lgray
Copy link

lgray commented Feb 9, 2025

Oh I see these failures are possibly related to #201 and #190, as the issue is in test_variants.

@ngoldbaum
Copy link
Contributor Author

Thanks for the help! Now that I know someone is blocked on this I'll get back to working on this library next week.

@martindurant
Copy link

I have been involved in this repo in the past, but not much recently. So I don't know the current state of the code well, but maybe I can help too.

@ngoldbaum
Copy link
Contributor Author

I spent some time over at #201. @milesgranger do you have any opinions about how to deal with CI being broken? Pin hypothesis for now maybe?

@milesgranger
Copy link
Owner

Can't thank you enough for helping out here @ngoldbaum, pinning hypothesis seems good for now.

@ngoldbaum
Copy link
Contributor Author

woohoo, green CI :)

@ngoldbaum ngoldbaum marked this pull request as ready for review February 13, 2025 02:55
@ngoldbaum
Copy link
Contributor Author

Before merging this I should do one final pass to make sure the unwrap() calls are safe. They're problematic if the mutex might get poisoned.

}

/// Compress input into the current compressor's stream.
pub fn compress(&mut self, input: &[u8]) -> PyResult<usize> {
crate::io::stream_compress(&mut self.inner, input)
crate::io::stream_compress(&mut self.inner.lock().unwrap(), input)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it eases things, I'm not adverse to adding parking_lot::Mutex

@lgray
Copy link

lgray commented Feb 13, 2025

Just FYI this still complains on import about not being marked as freethreaded-safe and reenables the GIL on import. Is that what we intend to have happen?

@ngoldbaum
Copy link
Contributor Author

Just FYI this still complains on import about not being marked as freethreaded-safe and reenables the GIL on import. Is that what we intend to have happen?

Yes, I still need to formally audit the codebase and add free-threaded support and CI. I’d also like to add some explicitly multithreaded tests. That will be a followup. After that is merged I’ll work on the wheel builds in a third PR.

@lgray
Copy link

lgray commented Feb 13, 2025

OK, wanted to check! Sounds good to me.

@ngoldbaum
Copy link
Contributor Author

So I think all the lock().unwrap() is fine - if there are any possible panics while waiting for the lock then they should be propagated to the user. PyO3's panic handler should then convert the panic into a Python exception. And indeed that's exactly what happens when I intentionally insert a panic into lz4::Compressor::compress:

diff --git a/src/lz4.rs b/src/lz4.rs
index f612ec9..614ee09 100644
--- a/src/lz4.rs
+++ b/src/lz4.rs
@@ -237,7 +237,9 @@ pub mod lz4 {

         /// Compress input into the current compressor's stream.
         pub fn compress(&mut self, input: &[u8]) -> PyResult<usize> {
-            crate::io::stream_compress(&mut self.inner.lock().unwrap(), input)
+            let inner = &mut self.inner.lock().unwrap();
+            panic!("Should be a python exception");
+            crate::io::stream_compress(inner, input)
         }
FAILED tests/test_variants.py::test_streams_compressor[lz4] - pyo3_runtime.PanicException: Should be a python exception

So I think we're good to go. @milesgranger go ahead and merge when ready :)

@milesgranger milesgranger merged commit 1ff8aab into milesgranger:master Feb 14, 2025
99 checks passed
@milesgranger
Copy link
Owner

Thank you, @ngoldbaum! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants