LoginSignup
9
8

More than 5 years have passed since last update.

ローカル関数で並列処理

Posted at

Poolはローカル関数を並列処理できないのでProcessを使う

#! /usr/local/bin/python
# -*- coding:utf-8

import multiprocessing
from time import sleep

def foo():
    def f(j,k):
        l = j + k
        print "no:%s" % i
        sleep(5 - i)
        print "unko%s" % l
    jobs = []
    for i in range(5):
        p = multiprocessing.Process(target=f,args=(i,100))
        jobs.append(p)
        p.start()
foo()
9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8