简体   繁体   中英

Tkinter how to start a thread only when the previous one finishes?

So I have this piece of code:

xlist = []
        if fl != '':
            with open(fl, 'r') as fin:
                for line in fin:
                    xlist.append(line)
        for line in xlist:
            Thread(target=self.downloadSongList, args=(line,)).start()

My question is, How can I start only 1 thread at a time? Because right now, the program starts all the threads together, but I want each thread to start only when the previous one ends. I tried to use .join() and queues, but nothing seems to work for me. Thanks!

You don't want a bunch of threads. Just create one thread, and put your 'for line in xlist' loop inside it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM