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

Bump version to 0.11.0 #989

Merged
merged 2 commits into from
Jun 28, 2020
Merged

Bump version to 0.11.0 #989

merged 2 commits into from
Jun 28, 2020

Conversation

kngwyu
Copy link
Member

@kngwyu kngwyu commented Jun 21, 2020

The first version that can be used with stable Rust.

  • Check the compatibility with rust-numpy

@davidhewitt
Copy link
Member

Shall we add a migration guide? I think we can mention stable Rust as well as PyClass: Send, maybe some other things too?

@kngwyu
Copy link
Member Author

kngwyu commented Jun 21, 2020

I think we can mention stable Rust as well as PyClass: Send

Sounds good 👍
You can push changes directly into this branch.

@davidhewitt
Copy link
Member

Cool I'll try to write this early evening today. Tomorrow morning at the latest.

@davidhewitt
Copy link
Member

Pushed a migration guide. I think it would be great to also merge #990 and @scalexm's recursive class attribute fix as part of 0.11.

Because `#[pyclass]` structs can be sent between threads by the Python interpreter, they must implement
`Send` to guarantee thread safety. This bound was added in PyO3 `0.11.0`.

This may "break" some code which previously was accepted, even though it was unsound. To resolve this,
Copy link
Member Author

Choose a reason for hiding this comment

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

We should note that 'if you are sure that your class is not sent to another thread, you can use unsafe impl Send for YourClass {}' first. Actually it's rare to send pyclass to another thread, and I saw some #[pyclass]es that have a raw pointer internally and need unsafe impl Send when investigating the effect of this change.

This may "break" some code which previously was accepted, even though it was unsound.

Also, we have to note that it's theoretically unsound, but not problematic when the class is not actually sent to another thread by:

  • Python's threading module
  • py.allow_threads and Py

Copy link
Member

Choose a reason for hiding this comment

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

We should note that 'if you are sure that your class is not sent to another thread, you can use unsafe impl Send for YourClass {}' first.

I don't think that's good advice. It undermines protections on the Rust side, too.

Also, we have to note that it's theoretically unsound, but not problematic when the class is not actually sent to another thread by:

I don't know about your experience, but I use the threading module quite a lot in Python, and objects are accessed freely from any thread there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the feedback.

I don't know about your experience, but I use the threading module quite a lot in Python, and objects are accessed freely from any thread there.

Maybe it's because I use Python mainly for machine learning research, where CPU/GPU bound is dominant.
Then I would rather take back my words... but I still think we should note that unsafe impl Sync can be the easiest fix. Maybe it's also helpful to link std::marker::Send or nomicon.

Copy link
Member

@davidhewitt davidhewitt Jun 23, 2020

Choose a reason for hiding this comment

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

I'm not keen on suggesting unsafe impl Send or unsafe impl Sync - to me that feels like the kind of hack where "I know that I'm not using threads now, so I can skip writing safe code". Later on this hack is forgotten, the code gets edited to include threading and suddenly very strange bugs / crashes / undefined behaviour.

EDIT: changed my mind. I'm ok to suggest adding unsafe impl Send as long as we carefully explain that the responsibility is on the user to ensure the type is also thread-safe. But we have to explain this really clearly - because the undefined behaviour the user might see if they get this wrong could be pretty bad.

(My description of using unsafe impl Send as a hack still applies when the user uses it to skip making a type thread-safe.)

Adding in a link to docs / nomicon would be fine though.

@kngwyu
Copy link
Member Author

kngwyu commented Jun 25, 2020

I added a sentence about unsafe impl Send. Please check it.

Copy link
Contributor

@programmerjake programmerjake left a comment

Choose a reason for hiding this comment

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

looks good to me!

@kngwyu kngwyu force-pushed the release-0.11 branch 3 times, most recently from b35e193 to 76e677e Compare June 27, 2020 12:48
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Sorry I was busy for a few days. I have a little wording suggestion, otherwise looks great!

Comment on lines 44 to 45
Or if you feel it hard to make your `#[pyclass]` struct automatically sendable
(e.g., in case it has a raw pointer), you can use `unsafe impl Send`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Or if you feel it hard to make your `#[pyclass]` struct automatically sendable
(e.g., in case it has a raw pointer), you can use `unsafe impl Send`.
Or in situations where you cannot change your `#[pyclass]` to automatically implement `Send`
(e.g., when it contains a raw pointer), you can use `unsafe impl Send`.

@kngwyu
Copy link
Member Author

kngwyu commented Jun 27, 2020

Thanks!

@kngwyu kngwyu merged commit e3218dd into master Jun 28, 2020
@kngwyu kngwyu deleted the release-0.11 branch June 28, 2020 05:01
@kngwyu kngwyu restored the release-0.11 branch June 28, 2020 05:01
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