1
我想我的腳本使用線程轉換爲更涼爽多(與Python 3.2和concurrent.futures
,但這段代碼崩潰executor.map和非terating參數
with ThreadPoolExecutor(max_workers=MAX_THREADS) as executor:
for result in executor.map(lambda h:
validate_hostname(h, pci_ids, options.verbose),
get_all_hostnames()):
我得到錯誤_pickle.PicklingError: Can't pickle <class 'function'>: attribute lookup builtins.function failed
。當閱讀this answer我認爲問題是,它是不可能有lambda表達式爲executor.map()
參數,併爲了使executor.map()
我需要開發一個參數的功能,但這些pci_ids
和options.verbose
是可變的,所以我不能指定它們作爲幫助功能中的固定值。
任何想法該怎麼辦?
哦,對了,謝謝你! – mcepl 2012-02-03 07:31:37
爲我工作,THX!但是應該避免在生成器表達式足夠時實例化列表,因此您應該更改爲'executor.map(validate,((host,pci_ids,options.verbose)for get_all_hostnames())) – georg 2016-02-10 21:23:27