2016-12-03 33 views
0

私はPythonでマルチプロセッシングを使ってファイルを読み込もうとしています。ここで小さな例です:PythonマルチプロセッシングThreadPool

import multiprocessing 
from time import * 

class class1(): 
    def function(self, datasheetname): 
     #here i start reading my datasheet 

if __name__ == '__main__': 
    #Test with multiprosessing 
    pool = multiprocessing.Pool(processes=4) 
    pool.map(class1("Datasheetname")) 
    pool.close() 

今、私は次のエラーを取得する:

このボードでは他のスレッドで

TypeError: map() missing 1 required positional argument: 'iterable'

私はThreadPoolのでこれを行うためのヒントを得たが、私はしません。実行する方法。何か案は?

+0

は、あなたが並列にこれを実行する必要がありますか、またはあなたはCSV/Excelシートの束を読み込む必要がありますか?後者の場合は、[pandas.read_csv](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html)または[pandas.read_excel](http:// pandas .pydata.org/pandas-docs/stable/generated/pandas.read_excel.html)。これは、単一の呼び出しで複数のファイル/シートを読み込むことができます。 – David

答えて

2

Pool.map

map(func, iterable[, chunksize])

A parallel equivalent of the map() built-in function (it supports only one iterable argument though). It blocks until the result is ready.

This method chops the iterable into a number of chunks which it submits to the process pool as separate tasks. The (approximate) size of these chunks can be specified by setting chunksize to a positive integer.

あなたは各要素が各工程での引数としてターゲットfuncに渡されたの反復可能に合格する必要があります。

例:

def function(sheet): 
    # do something with sheet 
    return "foo" 

pool = Pool(processes=4) 
result = pool.map(function, ['sheet1', 'sheet2', 'sheet3', 'sheet4']) 
# result will be ['foo', 'foo', 'foo', 'foo'] 
関連する問題