import threading
import time
class ClockThread(threading.Thread):
def __init__(self, interval):
threading.Thread.__init__(self)
self.daemon = True
self.interval = interval
def run(self):
while True:
print("The time is %s" % time.ctime())
time.sleep(self.interval)
t = ClockThread(1)
t.start()
time.sleep(5)
this is my code.i use is ok,but when i use in console if find this code can’t stop
like this
The time is Tue Jun 25 15:09:44 2024
The time is Tue Jun 25 15:09:45 2024
The time is Tue Jun 25 15:09:46 2024
The time is Tue Jun 25 15:09:47 2024
The time is Tue Jun 25 15:09:48 2024
# Normally the process would have stopped here
The time is Tue Jun 25 15:09:49 2024
The time is Tue Jun 25 15:09:50 2024
The time is Tue Jun 25 15:09:51 2024
The time is Tue Jun 25 15:09:52 2024
The time is Tue Jun 25 15:09:53 2024
The time is Tue Jun 25 15:09:54 2024
The time is Tue Jun 25 15:09:55 2024
The time is Tue Jun 25 15:09:56 2024
The time is Tue Jun 25 15:09:57 2024
then i find i can use in console ,i use t.is_alive(),it’s also True
it’s supposed to be false under normal circumstances,then i use t._stop() report an error
assert not lock.locked()
AssertionError
and i use t._tstate_lock.release_lock() or t._tstate_lock.release() (What’s the difference between them )
and t._stop() and t.is_alive() ,it have been False ,but the process is in progress
enter image description here
could everyone know whether it is the console Mechanism problem?
No_no_Me is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.