Context that raises an exception if process is blocking. Uses ``SIGALRM`` to detect blocking functions.
(timeout)
| 40 | |
| 41 | @contextmanager |
| 42 | def blockdetection(timeout): |
| 43 | """Context that raises an exception if process is blocking. |
| 44 | |
| 45 | Uses ``SIGALRM`` to detect blocking functions. |
| 46 | """ |
| 47 | if not timeout: |
| 48 | yield |
| 49 | else: |
| 50 | old_handler = signals['ALRM'] |
| 51 | old_handler = None if old_handler == _on_blocking else old_handler |
| 52 | |
| 53 | signals['ALRM'] = _on_blocking |
| 54 | |
| 55 | try: |
| 56 | yield signals.arm_alarm(timeout) |
| 57 | finally: |
| 58 | if old_handler: |
| 59 | signals['ALRM'] = old_handler |
| 60 | signals.reset_alarm() |
| 61 | |
| 62 | |
| 63 | def sample_mem(): |
nothing calls this directly
no test coverage detected