py.lib

Yohn Y. 2021-02-21 Parent:cab7fedf8432 Child:1668cc57225b

17:10227cc154fa Go to Latest

py.lib/Alarm.py

* Исправление ряда тупых ошибок в миграторе

History
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 from signal import SIGALRM, alarm, signal
6 class AlarmTimeout(Exception): pass
8 def _handler(sig, frame):
9 raise AlarmTimeout('Operation timeout')
11 class MkAlarm(object):
12 def __init__(self, timeout):
13 signal(SIGALRM, _handler)
14 alarm(timeout)
16 def __enter__(self):
17 pass
19 def __exit__(self, eType, eObj, tb):
20 if eObj == None:
21 alarm(0)
23 def __del__(self):
24 alarm(0)