Reacquire the GIL when handing errors in the read method of file_io's BufferedInputStream.
PiperOrigin-RevId: 316120310 Change-Id: I905e2c8652b977c154618c2e4d870dd2925a7234
This commit is contained in:
parent
588854df78
commit
0bf070c54d
@ -389,6 +389,18 @@ class FileIoTest(test.TestCase):
|
|||||||
self.assertEqual("t", f.read(1))
|
self.assertEqual("t", f.read(1))
|
||||||
self.assertEqual("esting3\n\ntesting5", f.read())
|
self.assertEqual("esting3\n\ntesting5", f.read())
|
||||||
|
|
||||||
|
def testReadErrorReacquiresGil(self):
|
||||||
|
file_path = os.path.join(self._base_dir, "temp_file")
|
||||||
|
with file_io.FileIO(file_path, mode="r+") as f:
|
||||||
|
f.write("testing1\ntesting2\ntesting3\n\ntesting5")
|
||||||
|
with self.assertRaises(errors.InvalidArgumentError):
|
||||||
|
# At present, this is sufficient to convince ourselves that the change
|
||||||
|
# fixes the problem. That is, this test will seg fault without the change,
|
||||||
|
# and pass with it. Unfortunately, this is brittle, as it relies on the
|
||||||
|
# Python layer to pass the argument along to the wrapped C++ without
|
||||||
|
# checking the argument itself.
|
||||||
|
f.read(-2)
|
||||||
|
|
||||||
def testTell(self):
|
def testTell(self):
|
||||||
file_path = os.path.join(self._base_dir, "temp_file")
|
file_path = os.path.join(self._base_dir, "temp_file")
|
||||||
with file_io.FileIO(file_path, mode="r+") as f:
|
with file_io.FileIO(file_path, mode="r+") as f:
|
||||||
|
@ -229,7 +229,7 @@ PYBIND11_MODULE(_pywrap_file_io, m) {
|
|||||||
const auto status = self->ReadNBytes(bytes_to_read, &result);
|
const auto status = self->ReadNBytes(bytes_to_read, &result);
|
||||||
if (!status.ok() && !tensorflow::errors::IsOutOfRange(status)) {
|
if (!status.ok() && !tensorflow::errors::IsOutOfRange(status)) {
|
||||||
result.clear();
|
result.clear();
|
||||||
tensorflow::MaybeRaiseRegisteredFromStatus(status);
|
tensorflow::MaybeRaiseRegisteredFromStatusWithGIL(status);
|
||||||
}
|
}
|
||||||
py::gil_scoped_acquire acquire;
|
py::gil_scoped_acquire acquire;
|
||||||
return py::bytes(result);
|
return py::bytes(result);
|
||||||
|
Loading…
Reference in New Issue
Block a user