(self, exc_type, exc_val, exc_tb)
| 93 | return self |
| 94 | |
| 95 | def __exit__(self, exc_type, exc_val, exc_tb): |
| 96 | self._stop_event.set() |
| 97 | if self._monitor_thread is not None: |
| 98 | self._monitor_thread.join(timeout=2.0) |
| 99 | if self._monitor_thread.is_alive(): |
| 100 | print( |
| 101 | "Warning: Monitor thread did not stop cleanly", |
| 102 | file=sys.stderr, |
| 103 | ) |
| 104 | |
| 105 | # Wait for child profilers to complete naturally |
| 106 | self.wait_for_profilers() |
| 107 | |
| 108 | # Terminate any remaining profilers |
| 109 | with self._lock: |
| 110 | profilers_to_cleanup = list(self._spawned_profilers) |
| 111 | self._spawned_profilers.clear() |
| 112 | |
| 113 | for proc in profilers_to_cleanup: |
| 114 | self._cleanup_process(proc) |
| 115 | return False |
| 116 | |
| 117 | def _cleanup_process(self, proc, terminate_timeout=2.0, kill_timeout=1.0): |
| 118 | if proc.poll() is not None: |
nothing calls this directly
no test coverage detected