MCPcopy Index your code
hub / github.com/python/cpython / wait_stopped

Method wait_stopped

Lib/test/libregrtest/run_workers.py:433–453  ·  view source on GitHub ↗
(self, start_time: float)

Source from the content-addressed store, hash-verified

431 f"{exc!r}")
432
433 def wait_stopped(self, start_time: float) -> None:
434 # bpo-38207: RunWorkers.stop_workers() called self.stop()
435 # which killed the process. Sometimes, killing the process from the
436 # main thread does not interrupt popen.communicate() in
437 # WorkerThread thread. This loop with a timeout is a workaround
438 # for that.
439 #
440 # Moreover, if this method fails to join the thread, it is likely
441 # that Python will hang at exit while calling threading._shutdown()
442 # which tries again to join the blocked thread. Regrtest.main()
443 # uses EXIT_TIMEOUT to workaround this second bug.
444 while True:
445 # Write a message every second
446 self.join(1.0)
447 if not self.is_alive():
448 break
449 dt = time.monotonic() - start_time
450 self.log(f"Waiting for {self} thread for {format_duration(dt)}")
451 if dt > WAIT_KILLED_TIMEOUT:
452 print_warning(f"Failed to join {self} in {format_duration(dt)}")
453 break
454
455
456def get_running(workers: list[WorkerThread]) -> str | None:

Callers 1

stop_workersMethod · 0.80

Calls 5

format_durationFunction · 0.85
print_warningFunction · 0.70
joinMethod · 0.45
is_aliveMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected