python多线程 简单例子

时间:2022-08-26 18:36:12

多线程, 简单的理解就是让我们可以同时做多件事情, 以下为简单例子.

import threading
def first():
print("do one thing")

def second():
print("do another thing")

threads = []

t1 = threading.Thread(target = first)
threads.append(t1)

t2 = threading.Thread(target = second)
threads.append(t2)

if __name__ == '__main__':
for t in threads:
t.start()