-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
[internal] Leverage PyO3 type conversions #13618
Conversation
# Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
Thank you again @mejrs and @davidhewitt, this type of change is awesome! |
@@ -110,7 +110,7 @@ def capture_snapshots( | |||
scheduler: PyScheduler, | |||
session: PySession, | |||
path_globs_and_root_tuple_wrapper: _PathGlobsAndRootCollection, | |||
) -> tuple[PySnapshot, ...]: ... | |||
) -> list[PySnapshot]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that PyO3 returns Vec<>
, I figured we can lean into it - not worth the eager type conversion to tuple.
.0 | ||
.core | ||
.executor | ||
.enter(|| py.allow_threads(|| py_scheduler.0.metrics(&py_session.0))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The allow_threads is new.
.workunit_store() | ||
.encode_observations() | ||
.map_err(PyException::new_err)?; | ||
let observations = py.allow_threads(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow_threads
is new
core | ||
.executor | ||
.block_on(future::try_join_all(snapshot_futures)) | ||
let snapshot_futures = path_globs_and_roots |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was moved into allow_threads. Same with processing the result
This reverts commit 3c9a7ff. [ci skip-build-wheels]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great change! Thanks.
We can let PyO3 write the type conversion code for us, as explained in https://pyo3.rs/v0.15.0/conversions/tables.html. This makes our code simpler to read and also allows us to use
py.allow_threads(||)
in more places.