Skip to content

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

Description

@stuhood

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`
  ..
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions