| 1245 | } |
| 1246 | |
| 1247 | void WatchVariable(PyObject* v) { |
| 1248 | tensorflow::Safe_PyObjectPtr handle(PyObject_GetAttrString(v, "handle")); |
| 1249 | if (handle == nullptr) { |
| 1250 | return; |
| 1251 | } |
| 1252 | tensorflow::int64 id = FastTensorId(handle.get()); |
| 1253 | |
| 1254 | if (!PyErr_Occurred()) { |
| 1255 | this->Watch(id); |
| 1256 | } |
| 1257 | |
| 1258 | tensorflow::mutex_lock l(watched_variables_mu_); |
| 1259 | auto insert_result = watched_variables_.emplace(id, v); |
| 1260 | |
| 1261 | if (insert_result.second) { |
| 1262 | // Only increment the reference count if we aren't already watching this |
| 1263 | // variable. |
| 1264 | Py_INCREF(v); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | PyObject* GetVariablesAsPyTuple() { |
| 1269 | tensorflow::mutex_lock l(watched_variables_mu_); |
no test coverage detected