Skip to content

Instantly share code, notes, and snippets.

@emrahgunduz
Created April 13, 2021 09:47
Show Gist options
  • Save emrahgunduz/58a3771c1923c2e159f549818dab7d59 to your computer and use it in GitHub Desktop.
Save emrahgunduz/58a3771c1923c2e159f549818dab7d59 to your computer and use it in GitHub Desktop.
Simple thread safe process timer
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