Skip to content

Instantly share code, notes, and snippets.

@alfredplpl
Last active August 29, 2015 14:22
Show Gist options
  • Save alfredplpl/5bd6d4ab9687e7f39f5e to your computer and use it in GitHub Desktop.
Save alfredplpl/5bd6d4ab9687e7f39f5e to your computer and use it in GitHub Desktop.
Pythonでよく迷うプロセス間のメモリ共有のサンプルを書きました。
# -*- coding: utf-8 -*-
# This code is distributed under the 3-Clause BSD license (New BSD license).
# 基本的に作者の名前を書いていただければ、商用利用も可能です。なお、保証はいたしかねます。
from multiprocessing import Manager,Pool
def f(param):
l,s=param
for i in range(10):
t=[x+i+s for x in l]
return t
if __name__ == '__main__':
manager = Manager()
NTASK = 5
l = manager.list(range(10))
print l
pool=Pool(4)
params=[(l,s) for s in range(NTASK)]
print params
ts = pool.map(f,params)
print ts
__author__ = 'alfredplpl'
# References: http://docs.python.jp/2.6/library/multiprocessing.html
# ライセンスに関する参考URL: http://osdn.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license
# Copyright (c) 2015, alfredplpl
# All rights reserved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment