Created
April 13, 2021 09:47
-
-
Save emrahgunduz/58a3771c1923c2e159f549818dab7d59 to your computer and use it in GitHub Desktop.
Simple thread safe process timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Lock | |
import time | |
class Took: | |
def __init__ ( self ): | |
self.__lock = Lock() | |
with self.__lock: | |
self.__start = time.time() | |
self.__total = time.time() | |
def re_init ( self ): | |
with self.__lock: | |
self.__start = time.time() | |
self.__total = time.time() | |
def single ( self ) -> float: | |
with self.__lock: | |
diff = time.time() - self.__start | |
self.__start = time.time() | |
return diff | |
def total ( self ) -> float: | |
with self.__lock: | |
diff = time.time() - self.__total | |
return diff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment