python,实现多线程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/littlle_yan/article/details/83658125

多线程:

#-*- coding:utf-8 -*-
import threading
import time
def target():
    print("the current threading %s is runing"%(threading.current_thread().name))
    seed = ["a", "b", "c"]
    for each in seed:
        print('the current threading %s is runing,hello:'%(threading.current_thread().name),each)
    time.sleep(2)
    print("the current threading %s is ended"%(threading.current_thread().name))

if __name__ == '__main__':
    threads = []
    thread1 = threading.Thread(target=target)
    threads.append(thread1)
    thread2 = threading.Thread(target=target)
    threads.append(thread2)
    thread3 = threading.Thread(target=target)
    threads.append(thread3)
    for t in threads:
        t.start()

输出结果为:

猜你喜欢

转载自blog.csdn.net/littlle_yan/article/details/83658125