【发布时间】:2012-04-09 01:32:18
【问题描述】:
使用下面的代码,我得到了奇怪的输出:
import sys
from multiprocessing import Process
import time
from time import strftime
now =time.time()
print time.strftime("%Y%m%d %H:%M:%S", time.localtime(now))
fr= [1,2,3]
for row in fr:
print 3
print 1
def worker():
print 'worker line'
time.sleep(1)
sys.exit(1)
def main():
print 'start worker'
Process(target=worker, args=()).start()
print 'main line'
if __name__ == "__main__":
start_time = time.time()
main()
end_time = time.time()
duration = end_time - start_time
print "Duration: %s" % duration
输出是:
20120324 20:35:53
3
3
3
1
start worker
main line
Duration: 0.0
20120324 20:35:53
3
3
3
1
worker line
我想我会得到这个:
20120324 20:35:53
3
3
3
1
start worker
worker line
main line
Duration: 1.0
为什么要运行两次?在 WinX64 上使用 python 2.7:
20120324 20:35:53
3
3
3
1
worker line
【问题讨论】:
标签: python multiprocessing main