| 1221 | } |
| 1222 | |
| 1223 | void mitk::nnInteractiveTool::EndSession() |
| 1224 | { |
| 1225 | if (!this->IsSessionRunning()) |
| 1226 | return; |
| 1227 | |
| 1228 | if (m_Impl->Remote) |
| 1229 | { |
| 1230 | // Release the server lease right away so the slot frees up for other users |
| 1231 | // instead of waiting for the idle reaper. close() is best-effort and |
| 1232 | // idempotent server-side; swallow errors so teardown always completes. |
| 1233 | try |
| 1234 | { |
| 1235 | m_Impl->GetPythonContext()->Execute( |
| 1236 | "session.close()\n" |
| 1237 | "del session\n"); |
| 1238 | } |
| 1239 | catch (const Exception& e) |
| 1240 | { |
| 1241 | MITK_WARN << "nnInteractive: error while releasing the remote session (ignored): " |
| 1242 | << e.GetDescription(); |
| 1243 | } |
| 1244 | } |
| 1245 | else |
| 1246 | { |
| 1247 | std::ostringstream pyCommands; pyCommands |
| 1248 | << "session._reset_session()\n" |
| 1249 | << "del session.network\n" |
| 1250 | << "del session\n"; |
| 1251 | |
| 1252 | if (m_Impl->GetBackend() == Backend::CUDA) |
| 1253 | pyCommands << "torch.cuda.empty_cache()\n"; |
| 1254 | |
| 1255 | m_Impl->GetPythonContext()->Execute(pyCommands.str()); |
| 1256 | } |
| 1257 | |
| 1258 | m_Impl->DestroyPythonContext(); |
| 1259 | |
| 1260 | m_Impl->Remote = false; |
| 1261 | m_Impl->HeartbeatIntervalMs = 0; |
| 1262 | m_Impl->SessionReferenceDataTimeStep = 0; |
| 1263 | m_Impl->SessionWorkingDataTimeStep = 0; |
| 1264 | m_Impl->ClearLastInteraction(); |
| 1265 | m_Impl->UndoRefreshPending = false; |
| 1266 | |
| 1267 | this->SessionEndedEvent.Send(); |
| 1268 | } |
| 1269 | |
| 1270 | bool mitk::nnInteractiveTool::IsRemoteSession() const |
| 1271 | { |
no test coverage detected