前端之家收集整理的这篇文章主要介绍了
Python 创建函数并将其作为单进程的完整代码,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣Python 创建
函数并将其作为单进程的完整
代码的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。<br>
# 编程之家 (jb51.cc)
import multiprocessing
import time
def worker(interval):
n = 5
while n > 0:
print("The time is {0}".format(time.ctime()))
time.sleep(interval)
n -= 1
if __name__ == "__main__":
p = multiprocessing.Process(target = worker,args = (3,))
p.start()
print "p.pid:",p.pid
print "p.name:",p.name
print "p.is_alive:",p.is_alive()
结果:
p.pid:
8736
p.name: Process
-1
p.is_alive: True
The time is Tue Apr
21
20:
55:
12
2015
The time is Tue Apr
21
20:
55:
15
2015
The time is Tue Apr
21
20:
55:
18
2015
The time is Tue Apr
21
20:
55:
21
2015
The time is Tue Apr
21
20:
55:
24
2015
原文链接:https://www.f2er.com/python/526818.html