If use_stack is True, this will stop the currently running timer and restore the previous timer on the stack if that exists. Note if use_stack is True, fn_name will be ignored. If use_stack is False, this will just stop timing the timer fn_name.
(fn_name=None, use_stack=True)
| 74 | |
| 75 | |
| 76 | def stop(fn_name=None, use_stack=True): |
| 77 | """ |
| 78 | If use_stack is True, this will stop the currently running timer and restore |
| 79 | the previous timer on the stack if that exists. Note if use_stack is True, |
| 80 | fn_name will be ignored. |
| 81 | |
| 82 | If use_stack is False, this will just stop timing the timer fn_name. |
| 83 | """ |
| 84 | global _running_timer, _disable_all |
| 85 | |
| 86 | if _disable_all: |
| 87 | return |
| 88 | |
| 89 | if use_stack: |
| 90 | if _running_timer is not None: |
| 91 | stop(_running_timer, use_stack=False) |
| 92 | if len(_timer_stack) > 0: |
| 93 | _running_timer = _timer_stack.pop() |
| 94 | start(_running_timer, use_stack=False) |
| 95 | else: |
| 96 | _running_timer = None |
| 97 | else: |
| 98 | print("Warning: timer stopped with no timer running!") |
| 99 | else: |
| 100 | if _start_times[fn_name] > -1: |
| 101 | ender.record() |
| 102 | ender.synchronize() |
| 103 | _total_times[fn_name] += starter.elapsed_time(ender) |
| 104 | else: |
| 105 | print("Warning: timer for %s stopped before starting!" % fn_name) |
| 106 | |
| 107 | |
| 108 | def print_stats(): |