美文网首页
2021-12-29 python 生产者消费者

2021-12-29 python 生产者消费者

作者: scoot929 | 来源:发表于2021-12-29 16:34 被阅读0次
    import csv
    import os
    import shutil
    from os import getenv
    import pandas as pd
    from mfg_core import *
    from multiprocessing import JoinableQueue, Process
    
    
    def producer(q):
        for root, dirs, files in os.walk("work", topdown=False):
            for name in files:
                file = os.path.join(root, name)
                logger.info(f'生产了一个file: {name}')
                q.put(file)
        q.join()
    
    
    def consumer(q):
        while True:
            file = q.get()
            logger.info(f'获得了一个file: {file}')
            q.task_done()
    
    logger = logging.getLogger(__name__)
    
    if __name__ == '__main__':
        jq = JoinableQueue()
        p = Process(target=producer, args=(jq,))
        p.start()
        for i in range(7):
            c = Process(target=consumer, args=(jq,))
            c.daemon = True
            c.start()
        p.join()
    

    相关文章

      网友评论

          本文标题:2021-12-29 python 生产者消费者

          本文链接:https://www.haomeiwen.com/subject/fkovqrtx.html