Help us understand the problem. What is going on with this article?

threading.enumerate

threading.enumerateで生存中のThreadオブジェクト全てのリストを取得できます。

import logging
import threading
import time

logging.basicConfig(level=logging.DEBUG, format='%(threadName)s: %(message)s')


def worker1():
    logging.debug('start')
    time.sleep(5)
    logging.debug('end')

if __name__ == '__main__':
    #threads = []
    for _ in range(5):
        t = threading.Thread(target=worker1)
        t.setDaemon(True)
        t.start()
        #threads.append(t)

    for thread in threading.enumerate():
        if thread is threading.currentThread():
            print(thread)
            continue
        thread.join()
Thread-1: start
Thread-2: start
Thread-3: start
Thread-4: start
Thread-5: start
<_MainThread(MainThread, started 4599717312)>
Thread-1: end
Thread-2: end
Thread-5: end
Thread-4: end
Thread-3: end
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away