-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
에러발생합니다2
24.01.21 16:17 작성 조회수 93
0
#Context Manager and Contextlib, __enter__,__exit__
#Ex1
import time
class ExcuteTimer(object):
def __init__(self,msg):
self._msg=msg
def __enter__(self):
self._start=time.monotonic()
return self._start
def __exit__(self,exc_type,exc_value,exc_traceback):
if exc_type:
print("Logging exception {}".format((exc_type,exc_value,exc_traceback)))
else:
print("{} {} s".format(self._msg, time.monotonic()-self._start))
return True
with ExcuteTimer('Start! job') as v:
print('Received start monotonic1:{}'.format(v))
for i in range(1000000):
pass
raise Exception('Raise! Exception!')
답변을 작성해보세요.
0
답변 1