Backround timer

i want to set a backround timer to some of my code can smb help please with an example of how to do it correctly? Answer as soon as possible.


What does this mean? When you run the code, exactly what should happen differently from what already happens, and how should it be different?

Please also read the pinned thread in order to understand how to show code with proper formatting, and this off-site guidance to try to focus the code on the part that is relevant to the problem you are encountering. That will make it easier for others to understand the problem, and to quote the code in order to talk about specific parts and explain concepts.

With respect: you are not in a position to make demands.

1 Like

i mean i want to have a quiz running which stops after a certaiin amount of time.The problem is that i cannnot get the quiz and the timer to run simultaneously. If you could help me it would be my pleasure.

i have a nice one i think

from time import perf_counter as timer

class Chrono:
    """Class to measure time intervals and store timing information."""
    def __init__(self):
        """Get current time in a list."""
        self.bench = [timer()]

    def mark(self, tot=False, precision=2, layout="min"):
        """Mark a new event and return the time elapsed since the begining or previous marker.
        Args:
            tot (bool): Default (False) result with previous marker. (True) with the first marker.
            precision (int): Default (2), seconds precision.
            layout (str): Default ("min") display min or ("sec") seconds only.
        Returns:
            str: Time elapsed in the specified format."""
        self.bench.append(timer())
        seconds_elapsed = self.bench[-1] - self.bench[-2] if not tot else self.bench[-1] - self.bench[0]
        return f"{seconds_elapsed:.{precision}f} sec." if layout == "sec" else f"{seconds_elapsed // 60:.0f} min. {seconds_elapsed % 60:.{precision}f} sec."


# usage
your_record = Chrono() # initilisation
blah bla bla your 
print (f" check time: {your_record.mark()}") # or with option in the fonction like precision min or sec or tot set to True

i fixed dont worry thank you for the help to eveyone. i just didnt use threads correctly. appreciate all the assistance though.