From fbd62e568b65a6f5dedeea173d23dd2b28828e43 Mon Sep 17 00:00:00 2001 From: Derek Murray Date: Thu, 2 Aug 2018 11:07:52 -0700 Subject: Add a defensive comment about the TOCTOU race --- tensorflow/python/lib/core/py_func.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tensorflow/python/lib/core') diff --git a/tensorflow/python/lib/core/py_func.cc b/tensorflow/python/lib/core/py_func.cc index 8c1fa31f05..a3c541da87 100644 --- a/tensorflow/python/lib/core/py_func.cc +++ b/tensorflow/python/lib/core/py_func.cc @@ -500,6 +500,12 @@ 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. " -- cgit v1.2.3