1 | #include <torch/csrc/distributed/rpc/unpickled_python_call.h> |
---|---|
2 | |
3 | #include <c10/util/C++17.h> |
4 | #include <torch/csrc/distributed/rpc/python_rpc_handler.h> |
5 | |
6 | namespace torch { |
7 | namespace distributed { |
8 | namespace rpc { |
9 | |
10 | UnpickledPythonCall::UnpickledPythonCall( |
11 | const SerializedPyObj& serializedPyObj, |
12 | bool isAsyncExecution) |
13 | : isAsyncExecution_(isAsyncExecution) { |
14 | auto& pythonRpcHandler = PythonRpcHandler::getInstance(); |
15 | pybind11::gil_scoped_acquire ag; |
16 | pythonUdf_ = pythonRpcHandler.deserialize(serializedPyObj); |
17 | } |
18 | |
19 | UnpickledPythonCall::~UnpickledPythonCall() { |
20 | // explicitly setting PyObject* to nullptr to prevent py::object's dtor to |
21 | // decref on the PyObject again. |
22 | // See Note [Destructing py::object] in python_ivalue.h |
23 | py::gil_scoped_acquire acquire; |
24 | pythonUdf_.dec_ref(); |
25 | pythonUdf_.ptr() = nullptr; |
26 | } |
27 | |
28 | c10::intrusive_ptr<Message> UnpickledPythonCall::toMessageImpl() && { |
29 | TORCH_INTERNAL_ASSERT( |
30 | false, "UnpickledPythonCall does not support toMessage()."); |
31 | } |
32 | |
33 | const py::object& UnpickledPythonCall::pythonUdf() const { |
34 | return pythonUdf_; |
35 | } |
36 | |
37 | } // namespace rpc |
38 | } // namespace distributed |
39 | } // namespace torch |
40 |