CleanupFunc doesn't need to do cleanup if _py_funcs is already destroyed.
authorAkshay Modi <nareshmodi@google.com>
Wed, 14 Feb 2018 00:17:55 +0000 (16:17 -0800)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 14 Feb 2018 00:21:28 +0000 (16:21 -0800)
PiperOrigin-RevId: 185606203

tensorflow/python/ops/script_ops.py

index 1b9071e..61e14ad 100644 (file)
@@ -176,7 +176,10 @@ class CleanupFunc(object):
     self._token = token
 
   def __del__(self):
-    _py_funcs.remove(self._token)
+    if _py_funcs is not None:
+      # If _py_funcs is None, the program is most likely in shutdown, and the
+      # _py_funcs object has been destroyed already.
+      _py_funcs.remove(self._token)
 
 
 def _internal_py_func(func, inp, Tout, stateful=None, eager=False, name=None):