首页 > 编程语言 > 详细

python 多进程,多线程简单的

时间:2021-04-24 16:22:57      阅读:19      评论:0      收藏:0      [点我收藏+]

python 多进程,多线程简单的

 

# -*- coding:utf-8 -*-
from time import ctime,sleep
import threading #线程
import multiprocessing #多进程

def talk(c,loop):
    for i in range(loop):
        print(" %s talk hello 51 zxw! %s" %(c,ctime()))
        sleep(3)
        
def write(c,loop):
    for i in range(loop):
        print(" %s wite hello 51 zxw! %s" %(c,ctime()))
        sleep(5)

threads = []
# t1 = threading.Thread(target=talk,args=("t1",2)) #多线程用这个
t1 = multiprocessing.Process(target=talk,args=("t1",2)) #多进程用这个
threads.append(t1)

# t2 = threading.Thread(target=write,args=("t1",2))
t2 = multiprocessing.Process(target=write,args=("t1",2))
threads.append(t2)

if __name__ == "__main__":
    for t in threads:
        t.start()
    for t in threads:
        t.join()
    print("all the end %s" %ctime())

 

python 多进程,多线程简单的

原文:https://www.cnblogs.com/zhenyu1/p/14696915.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!