Skip to content

How to call set_result() of future after return py::object to Python? #3593

Answered by MarshalX
MarshalX asked this question in Q&A
Discussion options

You must be logged in to vote

Before working with python object we need to asquire GIL, because it was released after finish of my method that returned future to Python.

My updated OnSuccess:

void Observer::OnSuccess() {
  pybind11::gil_scoped_acquire acquire;
   _future->attr("set_result")(10);
  pybind11::gil_scoped_release release;
}

Issue 2. Now I got Exception: EXC_BAD_ACCESS (code=1, address=0x8) during the access to set_result.
Solution: we need make a copy of object with increasing of ref count. It's possible using py::object constructor. For example return py::object{f};

Issue 3. I set result for some strange future that is not the same that I returned to Python (but should be?). In this case my future in pyt…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MarshalX
Comment options

Answer selected by MarshalX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant