py.lib

Yohn Y. 2022-08-13 Parent:ff755f64cda8

33:57f63bf31fd8 Go to Latest

py.lib/Alarm.py

* С разбегу влетел в type hinting, пришлось обкладывать костылями. И этот процесс судя по всему длительный, и место больное будет долго...

History
1 #!/usr/bin/python
2 # coding: utf-8
4 from signal import SIGALRM, alarm, signal
7 class AlarmTimeout(Exception):
8 pass
11 def _handler(sig, frame):
12 raise AlarmTimeout('Operation timeout')
15 class Alarm(object):
16 def __init__(self, timeout):
17 signal(SIGALRM, _handler)
18 alarm(timeout)
20 def __enter__(self):
21 pass
23 def __exit__(self, e_type, e_obj, tb):
24 if e_obj is None:
25 alarm(0)
27 def __del__(self):
28 alarm(0)