Skip to content

Commit

Permalink
Add __enter__ and __exit__ for CuFileDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
gigony committed Sep 28, 2021
1 parent b05a4b1 commit 9a4170d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/pybind11/filesystem/filesystem_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ void init_filesystem(py::module& fs)
py::arg("file_offset"), //
py::arg("buf_offset") = 0) //
.def("close", &CuFileDriver::close, doc::CuFileDriver::doc_close, py::call_guard<py::gil_scoped_release>()) //
.def(
"__enter__",
[](const std::shared_ptr<CuFileDriver>& fd) { //
return fd; //
}, //
py::call_guard<py::gil_scoped_release>())
.def(
"__exit__",
[](const std::shared_ptr<CuFileDriver>& fd, const py::object& type, const py::object& value,
const py::object& traceback) { //
fd->close(); //
}, //
py::call_guard<py::gil_scoped_release>())
.def("__repr__", [](const CuFileDriver& fd) {
return fmt::format("<cucim.clara.filesystem.CuFileDriver path:{}>", fd.path());
});
Expand Down

0 comments on commit 9a4170d

Please sign in to comment.