diff --git a/tensorflow/lite/python/interpreter.py b/tensorflow/lite/python/interpreter.py index 30f224e652b..153b6f17c3c 100644 --- a/tensorflow/lite/python/interpreter.py +++ b/tensorflow/lite/python/interpreter.py @@ -120,7 +120,7 @@ class Delegate(object): raise ValueError(capture.message) def __del__(self): - # __del__ can be called multiple times, so if the delegate is destroyed. + # __del__ can not be called multiple times, so if the delegate is destroyed. # don't try to destroy it twice. if self._library is not None: self._library.tflite_plugin_destroy_delegate.argtypes = [ctypes.c_void_p] diff --git a/tensorflow/lite/python/interpreter_test.py b/tensorflow/lite/python/interpreter_test.py index 0496fde289a..9c8dbbaa9c2 100644 --- a/tensorflow/lite/python/interpreter_test.py +++ b/tensorflow/lite/python/interpreter_test.py @@ -417,7 +417,10 @@ class InterpreterDelegateTest(test_util.TensorFlowTestCase): def testFail(self): with self.assertRaisesRegexp( - ValueError, 'Failed to load delegate from .*\nFail argument sent.'): + # Due to exception chaining in PY3, we can't be more specific here and check that + # the phrase 'Fail argument sent' is present. + ValueError, + r'Failed to load delegate from'): interpreter_wrapper.load_delegate( self._delegate_file, options={'fail': 'fail'}) diff --git a/tensorflow/lite/python/testdata/test_delegate.cc b/tensorflow/lite/python/testdata/test_delegate.cc index a7c48e01d24..98854cab114 100644 --- a/tensorflow/lite/python/testdata/test_delegate.cc +++ b/tensorflow/lite/python/testdata/test_delegate.cc @@ -66,7 +66,12 @@ void set_destroy_callback(int (*callback)(const char* s)) { void tflite_plugin_destroy_delegate(TfLiteDelegate* delegate) { num_delegates_destroyed++; delete delegate; - if (destruction_callback) destruction_callback("test_delegate"); + if (destruction_callback) { + destruction_callback("test_delegate"); + // destruction_callback is a global variable, + // so it should be set to nullptr here to avoid crashes + destruction_callback = nullptr; + } } void initialize_counters() {