I have a stopwatch of sorts going in the background using threading, and while it's updating the global variable, it doesn't change the output of my class attribute.
This is what I have:
import time
from threading import Thread
s = 0
m = 0
h = 0
stopped = False
def stopwatch():
global s
global m
global h
global stopped
while stopped == False:
s = s + 1
if s >= 60:
s = 0
m += 1
if m >= 60:
m = 0
h += 1
time.sleep(1)
class foo:
name = 'shirb'
time = str(h) + 'h' + str(m) + 'm' + str(s) +'s'
Thread(target = stopwatch).start()
input('press enter to stop the stopwatch')
stopped = True
print('Name: ' + foo.name + '\nTime: ' + foo.time)
Lets say I wait for one minute and 34 seconds. The output should be:
press enter to stop the stopwatch
Name: shirb
Time: 0h1m34s
But this is what it actually puts out:
press enter to stop the stopwatch
Name: shirb
Time: 0h0m0s
I have no idea what is causing it to not update. When I try to print the variable itself with "print(s)" i get the correct amount of seconds, so there is something wrong with the class attribute that I don't know how to fix.