0
最近我一直在学习Python的多处理功能和任务的延迟开始遇到问题用下面的代码与Python多处理
import syslog
from multiprocessing import Pool
def launcher(i):
time.sleep(i)
syslog.openlog('test', 0, syslog.LOG_LOCAL4)
syslog.syslog('{} {}'.format(i,datetime.now()))
if __name__ == '__main__':
pool=Pool(8)
pool.map(launcher,range(1,3000))
pool.close()
pool.join()
其背后的想法很简单:我需要得到消息的流动代替在我的系统日志中(每秒一条消息),但我想用多处理池在8个工作进程中产生它。
在我的系统日志(其是本地的/ var /日志/在我的Ubuntu系统日志),我有以下
Sep 17 17:17:57 test: 1 2015-09-17 17:17:57.225699
Sep 17 17:17:58 test: 2 2015-09-17 17:17:58.226957
Sep 17 17:18:00 test: 3 2015-09-17 17:18:00.229196
Sep 17 17:18:03 test: 4 2015-09-17 17:18:03.232390
Sep 17 17:18:07 test: 5 2015-09-17 17:18:07.236587
Sep 17 17:18:12 test: 6 2015-09-17 17:18:12.241737
Sep 17 17:18:18 test: 7 2015-09-17 17:18:18.247926
Sep 17 17:18:25 test: 8 2015-09-17 17:18:25.255169
Sep 17 17:18:29 test: 9 2015-09-17 17:18:29.258229
Sep 17 17:18:33 test: 10 2015-09-17 17:18:33.263454
Sep 17 17:18:42 test: 64 2015-09-17 17:18:42.272675
Sep 17 17:18:52 test: 33 2015-09-17 17:18:52.283012
Sep 17 17:19:01 test: 11 2015-09-17 17:19:01.290070
Sep 17 17:19:02 test: 12 2015-09-17 17:19:02.259826
首先,流程不统一,其次,无序。
如果是这样,原因是什么?
为什么linux进程调度程序像Python多处理那样工作?
有什么办法解决我的任务多处理?