Simple use case of python multithreading

Process: can be parallel 
Thread threading: can only be concurrent

"""
进程:可以并行的
线程threading:只能并发
"""
from threading import Thread


def login(user, password):
    print(f"user {user}, password {password}")


thread = []
user_list = ["a1", "a2"]
password = ["aaaa", "bbbb"]
for i in range(2):
    t = Thread(target=login, args=(user_list[i], password[i]))
    thread.append(t)

for t in thread:
    t.start()

for t in thread:
    t.join()
print("end")

 

Guess you like

Origin blog.csdn.net/chuancheng_zeng/article/details/114901011