aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/lib
diff options
context:
space:
mode:
authorGravatar Derek Murray <mrry@google.com>2018-08-01 14:31:15 -0700
committerGravatar GitHub <noreply@github.com>2018-08-01 14:31:15 -0700
commit8cd2d6fe9389e93a4182ae9287f2f8325913fe6c (patch)
treec853cd583e68c51d6d34192b55a3e532306ff4f1 /tensorflow/python/lib
parentd07564b2a4cb84b81e32bad7088ba5aec4aca630 (diff)
[tf.py_func()] Check Python interpreter state before call
Attempting to acquire the GIL in a destructor when the process is terminating can fail, leading to a hang. Fixes #21277.
Diffstat (limited to 'tensorflow/python/lib')
-rw-r--r--tensorflow/python/lib/core/py_func.cc5
1 files changed, 5 insertions, 0 deletions
diff --git a/tensorflow/python/lib/core/py_func.cc b/tensorflow/python/lib/core/py_func.cc
index 57139986af..8c1fa31f05 100644
--- a/tensorflow/python/lib/core/py_func.cc
+++ b/tensorflow/python/lib/core/py_func.cc
@@ -500,6 +500,11 @@ class PyFuncOp : public OpKernel {
call.ins.push_back(ctx->input(i));
}
+ OP_REQUIRES(
+ ctx, Py_IsInitialized(),
+ errors::FailedPrecondition("Python interpreter state is not initialized. "
+ "The process may be terminated."));
+
PyGILState_STATE py_threadstate;
py_threadstate = PyGILState_Ensure();
bool log_on_error;