(self)
| 36 | self.caller_thread = threading.current_thread() |
| 37 | |
| 38 | def run(self): |
| 39 | started = time.time() |
| 40 | self.condition.acquire() |
| 41 | while time.time() - started < self.timeout_secs and not self.completed: |
| 42 | self.condition.wait(self.timeout_secs - (time.time() - started)) |
| 43 | self.condition.release() |
| 44 | if not self.completed: |
| 45 | log = logging.getLogger("timeout_guard") |
| 46 | log.error("Call did not finish in time. Timeout:{}s PID: {}".format( |
| 47 | self.timeout_secs, |
| 48 | os.getpid(), |
| 49 | )) |
| 50 | |
| 51 | # First try dying cleanly, but in 10 secs, exit properly |
| 52 | def forcequit(): |
| 53 | time.sleep(10.0) |
| 54 | log.info("Prepared output, dumping threads. ") |
| 55 | print("Caller thread was: {}".format(self.caller_thread)) |
| 56 | print("-----After force------") |
| 57 | log.info("-----After force------") |
| 58 | import sys |
| 59 | import traceback |
| 60 | code = [] |
| 61 | for threadId, stack in sys._current_frames().items(): |
| 62 | if threadId == self.caller_thread.ident: |
| 63 | code.append("\n# ThreadID: %s" % threadId) |
| 64 | for filename, lineno, name, line in traceback.extract_stack(stack): |
| 65 | code.append('File: "%s", line %d, in %s' % (filename, lineno, name)) |
| 66 | if line: |
| 67 | code.append(" %s" % (line.strip())) |
| 68 | |
| 69 | # Log also with logger, as it is comment practice to suppress print(). |
| 70 | print("\n".join(code)) |
| 71 | log.info("\n".join(code)) |
| 72 | log.error("Process did not terminate cleanly in 10 s, forcing") |
| 73 | os.abort() |
| 74 | |
| 75 | forcet = threading.Thread(target=forcequit, args=()) |
| 76 | forcet.daemon = True |
| 77 | forcet.start() |
| 78 | print("Caller thread was: {}".format(self.caller_thread)) |
| 79 | print("-----Before forcing------") |
| 80 | import sys |
| 81 | import traceback |
| 82 | code = [] |
| 83 | for threadId, stack in sys._current_frames().items(): |
| 84 | code.append("\n# ThreadID: %s" % threadId) |
| 85 | for filename, lineno, name, line in traceback.extract_stack(stack): |
| 86 | code.append('File: "%s", line %d, in %s' % (filename, lineno, name)) |
| 87 | if line: |
| 88 | code.append(" %s" % (line.strip())) |
| 89 | |
| 90 | # Log also with logger, as it is comment practice to suppress print(). |
| 91 | print("\n".join(code)) |
| 92 | log.info("\n".join(code)) |
| 93 | os.kill(os.getpid(), signal.SIGINT) |
| 94 | |
| 95 |
nothing calls this directly
no test coverage detected