py.lib

Yohn Y. 2022-02-23 Parent:cab7fedf8432 Child:ff755f64cda8

23:1668cc57225b Go to Latest

py.lib/Alarm.py

. Рефакторинг бессмысленный и беспощадный

History
     1.1 --- a/Alarm.py	Sat Nov 27 12:29:59 2021 +0300
     1.2 +++ b/Alarm.py	Wed Feb 23 19:27:33 2022 +0300
     1.3 @@ -3,12 +3,15 @@
     1.4  
     1.5  from signal import SIGALRM, alarm, signal
     1.6  
     1.7 +
     1.8  class AlarmTimeout(Exception): pass
     1.9  
    1.10 +
    1.11  def _handler(sig, frame):
    1.12  	raise AlarmTimeout('Operation timeout')
    1.13  
    1.14 -class MkAlarm(object):
    1.15 +
    1.16 +class Alarm(object):
    1.17  	def __init__(self, timeout):
    1.18  		signal(SIGALRM, _handler)
    1.19  		alarm(timeout)
    1.20 @@ -16,8 +19,8 @@
    1.21  	def __enter__(self):
    1.22  		pass
    1.23  		
    1.24 -	def __exit__(self, eType, eObj, tb):
    1.25 -		if eObj == None:
    1.26 +	def __exit__(self, e_type, e_obj, tb):
    1.27 +		if e_obj is None:
    1.28  			alarm(0)
    1.29  	
    1.30  	def __del__(self):