Assume a main program that creates 5 threads, one at a time:
main.py
import threading
import time
from camera import Camera # this class inherits threading.Thread
# Initialize lock
lock = threading.RLock()
for i in range(5):
# Initialize camera threads
thread_1 = Camera(lock)
# Start videorecording
thread_1.start()
time.sleep(100)
# Signal thread to finish
thread_1.stop()
# Wait for thread to finish
thread_1.join()
del thread_1
When the thread is started, it prints its name with threading.currentThread().getName()
, resulting in the following output:
Thread-1
Thread-2
Thread-3
Thread-4
Thread-5
How come the name of the thread keeps increasing? I assumed that Python would reset the Thread-xxx number after deleting each thread after its execution with del thread_1
.
This was the expected output:
Thread-1
Thread-1
Thread-1
Thread-1
Thread-1