Python多线程的使用

# 导包
from threading import *
from time import *
def dance():
    print(current_thread())
    for i in range(3):
        print('跳舞...')
        sleep(0.2)

def sing():
    print(current_thread())
    for i in range(3):
        print('唱歌...')
        sleep(0.2)

if __name__ == '__main__':
    dance_thread = Thread(target=dance)
    sing_thread = Thread(target=sing)
    dance_thread.start()
    sing_thread.start()

# 创建线程
# Process(group=,target=,name=,args=,kwargs=)
# group线程组,目前只能使用None,一般不设置
# target 线程执行的目标
# name 线程名 默认为Thread-1 ...慢慢递增
# args 不定长参数,元组传入
# kwargs 不定长参数,字典传入

posted @ 2021-03-09 17:52  code-G  阅读(115)  评论(0编辑  收藏  举报