我試圖改進將資料從 CSV 匯入 Graphite/Go-Carbon DB 時間序列的腳本的執行時間。
這是決議所有 zipfile 并在函式 (execute_run) 中讀取它們的回圈:它嘗試了此代碼,但出現錯誤:
for idx4, Lst_f in enumerate(full_csvfile_paths):
if lst_metrics in Lst_f:
zip_file = Lst_f
with zipfile.ZipFile(zip_file) as zipobj:
print("Using ZipFile:",zipobj.filename)
#execute_run(zipobj.filename, confcsv_path, storage_type, serial)
output = subprocess.run(execute_run(zipobj.filename, confcsv_path, storage_type, serial),stdout=subprocess.PIPE)
print ("Return code: %i" % output.returncode)
print ("Output data: %s" % output.stdout)
錯誤:
Traceback (most recent call last):
File "./02-pickle-client.py", line 451, in <module>
main()
File "./02-pickle-client.py", line 361, in main
output = subprocess.run(execute_run(zipobj.filename, confcsv_path, storage_type, serial),stdout=subprocess.PIPE)
File "/usr/lib64/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib64/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib64/python3.6/subprocess.py", line 1240, in _execute_child
args = list(args)
TypeError: 'NoneType' object is not iterable
有沒有辦法執行X次函式:“ execute_run ”并控制正確的運行。
非常感謝您的幫助。
uj5u.com熱心網友回復:
問題可能是并行行程未設定為正確處理可迭代物件。而不是subprocess.run,我會推薦使用
multiprocessing.pool或這些檔案中multiprocessing.starmap指定的。
這可能看起來像這樣:
import multiprocessing as mp
# Step 1: Use multiprocessing.Pool() and specify number of cores to use (here I use 4).
pool = mp.Pool(4)
# Step 2: Use pool.starmap which takes a multiple iterable arguments
results = pool.starmap(My_Function, [(variable1,variable2,variable3) for i in data])
# Step 3: Don't forget to close
pool.close()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/407398.html
標籤:
下一篇:當我想停止執行緒內的執行時,我可以使用“Thread.currentThread().interrupt()”嗎?
