Вопрос по python – Альтернативные модели использования для многопроцессорной обработки Python, избегая распространения глобального состояния?

7

Error: User Rate Limit Exceeded

from multiprocessing import Pool
import numpy as np

src=None

def process(row):
    return np.sum(src[row])

def main():
    global src
    src=np.ones((100,100))

    pool=Pool(processes=16)
    rows=pool.map(process,range(100))
    print rows

if __name__ == "__main__":
    main()

Error: User Rate Limit Exceededglobal state bad!!!Error: User Rate Limit Exceeded

from multiprocessing import Pool
import numpy as np

def main():
    src=np.ones((100,100))

    def process(row):
        return np.sum(src[row])

    pool=Pool(processes=16)
    rows=pool.map(process,range(100))
    print rows

if __name__ == "__main__":
    main()

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

UpdateError: User Rate Limit ExceededsrcError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded luke14free
Error: User Rate Limit Exceeded timday

Ваш Ответ

1   ответ
6

from multiprocessing import Pool
import numpy as np

class RowProcessor(object):
    def __init__(self, src):
        self.__src = src
    def __call__(self, row):
        return np.sum(self.__src[row])

def main():
    src=np.ones((100,100))
    p = RowProcessor(src)

    pool=Pool(processes=16)
    rows = pool.map(p, range(100))
    print rows

if __name__ == "__main__":
    main()
Error: User Rate Limit Exceeded timday
Error: User Rate Limit Exceeded timday
Error: User Rate Limit Exceeded timday
Error: User Rate Limit Exceeded

Похожие вопросы