Python多处理Jits

时间:2013-10-01 05:41:52

标签: python multithreading multiprocessing

我试图执行像这样的多处理程序

recQ = eventQ = Queue()

def _getRecords():
    files=os.listdir(LOGDIR)
    for file in files:
       fileHeader = open(os.path.join(LOGDIR,file))
       reader = logf.LogfileReader(fileHeader)
       data = defaultdict(lambda: defaultdict(int))
       for record in fileHeader.readlines():
           recQ.put(record)                  
    recQ.put('Done')

def _makeEvents():
    while(True):
        rec = recQ.get()
        if not rec == 'Done':
            e = event._getOject(rec)
            eventQ.put(e)
        else: break
    eventQ.put('Done')

def _updateSQL():
    while(True):
        data = eventQ.get()
        if not data == 'Done':
            event = eventQ.get()
            sql._updateEvent(event)
        else: break

def _trigger():
    processes = []
    processes.append(Process(target = _getRecords(), args = ()))
    processes.append(Process(target = _makeEvents(), args = ()))
    processes.append(Process(target = _updateSQL(), args = ()))
    for process in processes:
        process.start()

if __name__ == '__main__':
    _trigger()

现在的问题是当我从for循环开始所有进程时,它们会一个接一个地执行。我在一些更简单的数据上尝试过类似的例子,它可以很好地处理它。任何人都可以告诉我我的代码有什么问题。

提前致谢:)

0 个答案:

没有答案