py.lib

Yohn Y. 2022-07-17 Parent:ff755f64cda8

28:d6032160c314 Go to Latest

py.lib/Alarm.py

. Переименовние log/slog_syslogger_tiny.py -> log/tiny_slog.py

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)