[英]Python processes fail to start
我在我的應用程序中運行以下代碼塊。 當使用python3.4運行它時,在屏幕上出現“ python意外退出”彈出窗口。 aOut文件中缺少的數據是一堆迭代的數據,並且是成塊的。 說列表中的0-1000個項目不存在,而其他項目有數據。 其他項目無需干預即可自行正常運行。
使用python2.7時,失敗的原因是列表中的〜3400-4400。
在日志記錄中,我看到,不對0-1000之間的進程(即process.start()調用)進行detect()調用,不會觸發detect方法。
我正在MAC OS Sierra上執行此操作。 這是怎么回事 有沒有更好的方法可以實現我的目的?
def detectInBatch (aList, aOut):
#iterate through the objects
processPool = []
pthreadIndex = 0
pIndex = 0
manager = Manager()
dict = manager.dict()
outline = ""
print("Threads: ", getMaxThreads()) # max threads is 20
for key in aList:
print("Key: %s, pIndex: %d"%(key.key, pIndex))
processPool.append(Process(target=detect, args=(key.key, dict)))
pthreadIndex = pthreadIndex + 1
pIndex = pIndex + 1
#print("Added for %d" %(pIndex))
if(pthreadIndex == getMaxThreads()):
print("ProcessPool size: %d" %len(processPool))
for process in processPool:
#print("Started")
process.start()
#end for
print("20 Processes started")
for process in processPool:
#print("Joined")
process.join()
#end for
print("20 Processes joined")
for key in dict.keys():
outline = outline + dict.get(key)
#end for
dict.clear()
pthreadIndex = 0
processPool = []
#endif
#endfor
if(pthreadIndex != 0):
for process in processPool:
# print("End Start")
process.start()
#end for
for process in processPool:
# print("End done")
process.join()
#end for
for key in dict.keys():
print ("Dict: " + dict.get(key))
outline = outline + dict.get(key)
#end for
#endif
aOut.write(outline)
#end method detectInBatch
為了避免“意外退出”,請嘗試忽略帶有
try:
your_loop()
except:
pass
然后,進行一些日志記錄以跟蹤根本原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.