MCPcopy Create free account
hub / github.com/microsoft/debugpy / __exit__

Method __exit__

tests/debug/session.py:242–320  ·  view source on GitHub ↗
(self, exc_type, exc_val, exc_tb)

Source from the content-addressed store, hash-verified

240 return self
241
242 def __exit__(self, exc_type, exc_val, exc_tb):
243 log.info("Ending {0}.", self)
244
245 if self.timeline.is_frozen:
246 self.timeline.unfreeze()
247
248 # Only wait for exit if there was no exception in the test - if there was one,
249 # the debuggee might still be waiting for further requests.
250 if exc_type is None:
251 # If expected_exit_code is set to None, the debuggee is not expected to
252 # exit after this Session is closed (e.g. because another Session will
253 # attach to it later on).
254 if self.expected_exit_code is not None:
255 self.wait_for_exit()
256 else:
257 # Log the error, in case another one happens during shutdown.
258 log.swallow_exception(exc_info=(exc_type, exc_val, exc_tb))
259
260 if exc_type is None:
261 self.disconnect()
262 self.timeline.close()
263 else:
264 # If there was an exception, don't try to send any more messages to avoid
265 # spamming log with irrelevant entries - just close the channel and kill
266 # all the processes immediately. Don't close or finalize the timeline,
267 # either, since it'll likely have unobserved events in it.
268 if self.adapter is not None:
269 log.info("Killing {0}.", self.adapter_id)
270 try:
271 self.adapter.kill()
272 except Exception:
273 pass
274 if self.debuggee is not None:
275 log.info("Killing {0}.", self.debuggee_id)
276 try:
277 self.debuggee.kill()
278 except Exception:
279 pass
280 self.disconnect(force=True)
281
282 if self.adapter_endpoints is not None and self.expected_exit_code is not None:
283 log.info("Waiting for {0} to close listener ports ...", self.adapter_id)
284 timeout_start = time.time()
285 while self.adapter_endpoints.check():
286 if time.time() - timeout_start > 10:
287 log.warning("{0} listener ports did not close within 10 seconds", self.adapter_id)
288 break
289 time.sleep(0.1)
290
291 if self.adapter is not None:
292 log.info(
293 "Waiting for {0} with PID={1} to exit.",
294 self.adapter_id,
295 self.adapter.pid,
296 )
297 try:
298 self.adapter.wait(timeout=10)
299 except Exception:

Callers

nothing calls this directly

Calls 9

wait_for_exitMethod · 0.95
disconnectMethod · 0.95
infoMethod · 0.80
unfreezeMethod · 0.80
errorMethod · 0.80
closeMethod · 0.45
killMethod · 0.45
checkMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected