diff options
author | 2018-08-09 10:57:09 -0700 | |
---|---|---|
committer | 2018-08-09 10:57:41 -0700 | |
commit | 243b80849f8ff7a580efc3963067c732f4770d61 (patch) | |
tree | 7a86f8ba900be409b655f525998ff3c9bcb3ad30 /tensorflow/python/lib | |
parent | fe6b586e862bf7288e138d73f2e66cf8cef7eb26 (diff) | |
parent | fbd62e568b65a6f5dedeea173d23dd2b28828e43 (diff) |
Merge pull request #21319 from tensorflow:mrry-patch-1
PiperOrigin-RevId: 208075630
Diffstat (limited to 'tensorflow/python/lib')
-rw-r--r-- | tensorflow/python/lib/core/py_func.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tensorflow/python/lib/core/py_func.cc b/tensorflow/python/lib/core/py_func.cc index 7c107138be..fc02d6de0e 100644 --- a/tensorflow/python/lib/core/py_func.cc +++ b/tensorflow/python/lib/core/py_func.cc @@ -507,6 +507,17 @@ class PyFuncOp : public OpKernel { call.ins.push_back(ctx->input(i)); } + // NOTE(mrry): There is a potential time-of-check-to-time-of-use race here. + // because it is possible that `Py_Finalize()` could be called in another + // thread between this check and the call to `PyGILState_Ensure()`, which + // will abort the process if `Py_Finalize()` has been called. A more robust + // solution would be welcome, but it is not obvious how to make this work + // using the current Python C API. + 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; |