Код: Выделить всё
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)
вот так
Код: Выделить всё
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
при нормальных обстоятельствах оно должно быть ложным , затем я использую t._stop(), сообщаю об ошибке
assert not lock.locked()
AssertionError
и использую t ._tstate_lock.release_lock() или t._tstate_lock.release() (в чем разница между ними)
и t._stop() и t.is_alive(), это было False, но процесс продолжаетсявведите описание изображения здесь
может ли кто-нибудь знать, проблема ли это в механизме консоли?
Подробнее здесь: https://stackoverflow.com/questions/786 ... -run-error