MCPcopy Create free account
hub / github.com/MITK/MITK / EndSession

Method EndSession

Modules/PythonSegmentation/src/mitknnInteractiveTool.cpp:1223–1268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1221}
1222
1223void 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
1270bool mitk::nnInteractiveTool::IsRemoteSession() const
1271{

Callers 5

DeactivatedMethod · 0.95
StartSessionMethod · 0.95
AbortSessionMethod · 0.95
OnTimePointChangedMethod · 0.95

Calls 8

IsSessionRunningMethod · 0.95
GetBackendMethod · 0.80
DestroyPythonContextMethod · 0.80
ClearLastInteractionMethod · 0.80
ExecuteMethod · 0.45
GetPythonContextMethod · 0.45
GetDescriptionMethod · 0.45
SendMethod · 0.45

Tested by

no test coverage detected