F
F
flex7r2020-02-27 20:32:15
Python
flex7r, 2020-02-27 20:32:15

Why isn't the thread running?

def _timer():
    timer = True
    while True:
        if timer == False:
            time.sleep(60)
            timer = True
t1 = threading.Thread(target=_timer)
t1.daemon = True
t1.start()
print("T2 LOADED")

Why is T2 LOADED not displayed in the console ?

Before this thread, there is another one that also uses sleep (), which is quietly loaded

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Caliostra, 2020-02-28
@N_XY

I understand the timer variable should change from the outside?
I'm not an expert, but it seems to me that the function does not see the external variable timer.
what can I suggest, I experimented a little, in general - try to wrap the timer variable in an object and pass it to the streams by reference (just pass it).
it worked for me like that. I will attach the screen with an example
code:
5e5867af135c6039891937.png
result:
5e5867ef9c99e314549805.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question