Check how many times the traceback is written in timeout x 2.5 seconds, or timeout x 3.5 seconds if cancel is True: 1, 2 or 3 times depending on repeat and cancel options. Raise an error if the output doesn't match the expect format.
(self, repeat=False, cancel=False, loops=1,
*, filename=None, fd=None)
| 634 | self.check_dump_traceback_threads(filename) |
| 635 | |
| 636 | def check_dump_traceback_later(self, repeat=False, cancel=False, loops=1, |
| 637 | *, filename=None, fd=None): |
| 638 | """ |
| 639 | Check how many times the traceback is written in timeout x 2.5 seconds, |
| 640 | or timeout x 3.5 seconds if cancel is True: 1, 2 or 3 times depending |
| 641 | on repeat and cancel options. |
| 642 | |
| 643 | Raise an error if the output doesn't match the expect format. |
| 644 | """ |
| 645 | timeout_str = str(datetime.timedelta(seconds=TIMEOUT)) |
| 646 | code = """ |
| 647 | import faulthandler |
| 648 | import time |
| 649 | import sys |
| 650 | |
| 651 | timeout = {timeout} |
| 652 | repeat = {repeat} |
| 653 | cancel = {cancel} |
| 654 | loops = {loops} |
| 655 | filename = {filename!r} |
| 656 | fd = {fd} |
| 657 | |
| 658 | def func(timeout, repeat, cancel, file, loops): |
| 659 | for loop in range(loops): |
| 660 | faulthandler.dump_traceback_later(timeout, repeat=repeat, file=file) |
| 661 | if cancel: |
| 662 | faulthandler.cancel_dump_traceback_later() |
| 663 | time.sleep(timeout * 5) |
| 664 | faulthandler.cancel_dump_traceback_later() |
| 665 | |
| 666 | if filename: |
| 667 | file = open(filename, "wb") |
| 668 | elif fd is not None: |
| 669 | file = sys.stderr.fileno() |
| 670 | else: |
| 671 | file = None |
| 672 | func(timeout, repeat, cancel, file, loops) |
| 673 | if filename: |
| 674 | file.close() |
| 675 | """ |
| 676 | code = code.format( |
| 677 | timeout=TIMEOUT, |
| 678 | repeat=repeat, |
| 679 | cancel=cancel, |
| 680 | loops=loops, |
| 681 | filename=filename, |
| 682 | fd=fd, |
| 683 | ) |
| 684 | trace, exitcode = self.get_output(code, filename) |
| 685 | trace = '\n'.join(trace) |
| 686 | |
| 687 | if not cancel: |
| 688 | count = loops |
| 689 | if repeat: |
| 690 | count *= 2 |
| 691 | header = (fr'Timeout \({timeout_str}\)!\n' |
| 692 | fr'{THREAD_HEADER}\n') |
| 693 | regex = expected_traceback(17, 26, header, min_count=count) |
no test coverage detected