系统相关
首页 > 系统相关> > python多进程处理

python多进程处理

作者:互联网

import threading


def task1():
    print("扔第二个苹果")



def task2():
    print("扔第三个苹果")


def main():
    # threading.Thread 创建一个线程
    thread1 = threading.Thread(target=task1())
    # 让线程执行
    thread1.start()
    thread2 = threading.Thread(target=task2())
    thread2.start()
    print("扔第一个苹果")

import time
def task1():
    time.sleep(5)



def main():
    start_time = time.time()
    thread1 = threading.Thread(target=task1())
    thread2 = threading.Thread(target=task1())
    thread1.start()
    thread2.start()
    # 让其他线程等待自己执行完成
    thread1.join()
    thread2.join()
    end_time = time.time()
    print(end_time - start_time)

标签:task1,处理,start,python,threading,thread2,thread1,time,进程
来源: https://blog.csdn.net/yuzhong_chen/article/details/120942064