我有一個主進程生成進程,然後這些進程將作業添加到主進程用於產生更多進程的隊列。並且,這工作正常約20秒,然後主進程停止產卵工作,即使它在隊列中有大量工作。Python隊列似乎正在死亡
這裏的作業過程的運行循環的代碼:
try:
page = self.fetch_page(self.url, self.timeout)
if page != None:
#do_stuff
pass
except Exception, e: #Log any errors
import traceback
self.log(str(traceback.format_exc(limit=10)), level="error")
self.log(str(e), level="error")
finally:
import os, signal
print "releasing Semaphore"
self.__sem.release()
#print "Joining pQueue" #these statements raise errors...
#self.__pqueue.join_thread()
#print "Joining lQueue"
#self.__log.join_thread()
print "exiting"
os._exit(1)
#os.kill(self.pid, signal.SIGTERM)
及這裏的派生的就業崗位主要工序中的代碼:
while True:
print "Waiting for url"
url = self.page_queue.get()
print "waiting for semaphore"
self.__sem.acquire()
print "semaphore recived"
process = self.process_handler(url, self.log_queue, self.__sem, self.page_queue)
process.start()
只是一個小範圍內,self.log_queue在產卵過程是自我.__登錄Job過程,self.page_queue在Job過程中是self .__ pqueue,而self .__ sem與Job過程中的self .__ sem相同。
的spawing過程通常掛在:
url = self.page_queue.get()
我敢肯定是有事情做與隊列打破時,工作進程終止他們完成寫入隊列前,但是這只是一個直覺。和self .__ pqueue.join_thread()引發了斷言錯誤。
如何實例化您的信號量?如果初始值太小,您將無法處理許多進程。 – 2011-05-07 19:07:10
你怎麼知道隊列中有很多工作? – 2011-05-07 21:39:07
@Cedric Julien它在主進程中初始化,然後作爲參數傳遞給進程。在約1進程的比率它初始化爲5 – Joshkunz 2011-05-10 18:20:10