https://blog.csdn.net/oatnehc/article/details/50616835
https://www.cnblogs.com/ArsenalfanInECNU/p/8989770.html
之前用python的多线程,总是处理不好进程和线程之间的关系。后来发现了join和setDaemon函数,才终于弄明白。下面总结一下。
1.使用join函数后,主进程会在调用join的地方等待子线程结束,然后才接着往下执行。
join使用实例如下:
-
import time
-
import random
-
import threading
-
class worker(threading.Thread):
-
def __init__(self):
-
threading.Thread.__init__(self)
-
def run(self):
-
t = random.randint(1,10)
-
time.sleep(t)