(*args, **kwargs)
| 659 | |
| 660 | @functools.wraps(obj) |
| 661 | def _wrapper(*args, **kwargs): |
| 662 | tmp = torch.multiprocessing.get_context(self.method) |
| 663 | func = _call_original_func |
| 664 | args = [obj.__name__, obj.__module__] + list(args) |
| 665 | results = tmp.Queue() |
| 666 | p = tmp.Process(target=TimedCall.run_process, args=(func, args, kwargs, results), daemon=self.daemon) |
| 667 | p.start() |
| 668 | |
| 669 | p.join(timeout=self.timeout_seconds) |
| 670 | |
| 671 | timeout_error = None |
| 672 | try: |
| 673 | if p.is_alive(): |
| 674 | # create an Exception |
| 675 | timeout_error = torch.multiprocessing.TimeoutError( |
| 676 | f"'{obj.__name__}' in '{obj.__module__}' did not finish in {self.timeout_seconds}s." |
| 677 | ) |
| 678 | if self.force_quit: |
| 679 | p.terminate() |
| 680 | else: |
| 681 | warnings.warn( |
| 682 | f"TimedCall: deadline ({self.timeout_seconds}s) " |
| 683 | f"reached but waiting for {obj.__name__} to finish." |
| 684 | ) |
| 685 | finally: |
| 686 | p.join() |
| 687 | |
| 688 | _del_original_func(obj) |
| 689 | res = None |
| 690 | try: |
| 691 | res = results.get(block=False) |
| 692 | except queue.Empty: # no result returned, took too long |
| 693 | pass |
| 694 | if isinstance(res, Exception): # other errors from obj |
| 695 | if hasattr(res, "traceback"): |
| 696 | raise RuntimeError(res.traceback) from res |
| 697 | raise res |
| 698 | if timeout_error: # no force_quit finished |
| 699 | raise timeout_error |
| 700 | return res |
| 701 | |
| 702 | return _wrapper |
| 703 |
nothing calls this directly
no test coverage detected