![](/img/trans.png)
[英]Can Python scripts created with 64bit Python be run on same version but 32 bit Python?
[英]Python: how to run several scripts (or functions) at the same time under windows 7 multicore processor 64bit
對此問題感到抱歉,因為Stackoverflow中有幾個示例。 我寫這篇文章是為了澄清我的一些疑問,因為我是Python語言的新手。
我寫了一個函數:
def clipmyfile(inFile,poly,outFile):
... # doing something with inFile and poly and return outFile
通常我這樣做:
clipmyfile(inFile="File1.txt",poly="poly1.shp",outFile="res1.txt")
clipmyfile(inFile="File2.txt",poly="poly2.shp",outFile="res2.txt")
clipmyfile(inFile="File3.txt",poly="poly3.shp",outFile="res3.txt")
......
clipmyfile(inFile="File21.txt",poly="poly21.shp",outFile="res21.txt")
我已經在本示例中閱讀了同時運行多個python程序的信息,並且可以使用(但我可能錯了)
from multiprocessing import Pool
p = Pool(21) # like in your example, running 21 separate processes
同時運行該功能並加快分析速度
我真的很誠實地說我不理解下一步。
在此先感謝您的幫助和建議
您提供的示例中使用的映射僅適用於接受一個參數的函數。 您可以在此處查看解決方案: 多個參數的Python multiprocessing pool.map
在您的情況下,您將要做的是(假設您有3個包含文件,多邊形,輸出的數組):
def expand_args(f_p_o):
clipmyfile(*f_p_o)
files = ["file1.txt", "file2.txt"]
polis = ["poli1.txt", "poly2.txt"]
outis = ["out1.txt", "out2.txt"]
len_f = len(files)
p = Pool()
p.map(expand_args, [(files[i], polis[i], outis[i]) for i in xrange(len_f)])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.