Skip to content

Instantly share code, notes, and snippets.

@emrahgunduz
Created Apr 13, 2021
Embed
What would you like to do?
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