MySQL

做最专业的DBA

Python 多进程

import multiprocessing
import time

def worker_1(interval):
print “worker_1”
time.sleep(interval)
print “end worker_1”

def worker_2(interval):
print “worker_2”
time.sleep(interval)
print “end worker_2”

def worker_3(interval):
print “worker_3”
time.sleep(interval)
print “end worker_3”

if name == “main“:
p1 = multiprocessing.Process(target = worker_1, args = (2,))
p2 = multiprocessing.Process(target = worker_2, args = (3,))
p3 = multiprocessing.Process(target = worker_3, args = (4,))

p1.start()
p2.start()
p3.start()

print("The number of CPU is:" + str(multiprocessing.cpu_count()))
for p in multiprocessing.active_children():
    print("child   p.name:" + p.name + "\tp.id" + str(p.pid))
print "END!!!!!!!!!!!!!!!!!"
阅读更多
个人分类: - - - Python
想对作者说点什么? 我来说一句

python进阶——多进程

1

scorpion_zs scorpion_zs

2016-11-18 16:39:09

阅读数:1587

没有更多推荐了,返回首页

不良信息举报

Python 多进程

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭