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

Consider adding support to py_fn for implicit GIL-releasing #260

Open
stuhood opened this issue Mar 17, 2021 · 0 comments
Open

Consider adding support to py_fn for implicit GIL-releasing #260

stuhood opened this issue Mar 17, 2021 · 0 comments

Comments

@stuhood
Copy link
Contributor

stuhood commented Mar 17, 2021

py_fn! currently requires a Python parameter, meaning that the GIL is always held when the function body is entered.

It would be very neat to not require this parameter, and when it was not included, release the GIL after preparing the arguments of the function and before calling it.

Concretely, this would reduce the boilerplate of "doing the right thing" (not holding the GIL through native code unless necessary) from:

fn my_function(py: Python, argument: String) -> Result<..> {
  py.allow_threads(|| {
    // do something with `argument`
    ..
  })
}

...to:

fn my_function(argument: String) -> Result<..> {
  // do something with `argument`
  ..
}
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

No branches or pull requests

1 participant