<legend id='0nkE9'><style id='0nkE9'><dir id='0nkE9'><q id='0nkE9'></q></dir></style></legend>

    <small id='0nkE9'></small><noframes id='0nkE9'>

    <tfoot id='0nkE9'></tfoot>
  1. <i id='0nkE9'><tr id='0nkE9'><dt id='0nkE9'><q id='0nkE9'><span id='0nkE9'><b id='0nkE9'><form id='0nkE9'><ins id='0nkE9'></ins><ul id='0nkE9'></ul><sub id='0nkE9'></sub></form><legend id='0nkE9'></legend><bdo id='0nkE9'><pre id='0nkE9'><center id='0nkE9'></center></pre></bdo></b><th id='0nkE9'></th></span></q></dt></tr></i><div id='0nkE9'><tfoot id='0nkE9'></tfoot><dl id='0nkE9'><fieldset id='0nkE9'></fieldset></dl></div>

        <bdo id='0nkE9'></bdo><ul id='0nkE9'></ul>
    1. 将复杂字典放入返回队列时,多处理进程不加入

      Multiprocessing process does not join when putting complex dictionary in return queue(将复杂字典放入返回队列时,多处理进程不加入)

          1. <legend id='ivBTa'><style id='ivBTa'><dir id='ivBTa'><q id='ivBTa'></q></dir></style></legend>
              <tbody id='ivBTa'></tbody>
          2. <tfoot id='ivBTa'></tfoot>
              • <bdo id='ivBTa'></bdo><ul id='ivBTa'></ul>

                <i id='ivBTa'><tr id='ivBTa'><dt id='ivBTa'><q id='ivBTa'><span id='ivBTa'><b id='ivBTa'><form id='ivBTa'><ins id='ivBTa'></ins><ul id='ivBTa'></ul><sub id='ivBTa'></sub></form><legend id='ivBTa'></legend><bdo id='ivBTa'><pre id='ivBTa'><center id='ivBTa'></center></pre></bdo></b><th id='ivBTa'></th></span></q></dt></tr></i><div id='ivBTa'><tfoot id='ivBTa'></tfoot><dl id='ivBTa'><fieldset id='ivBTa'></fieldset></dl></div>
              • <small id='ivBTa'></small><noframes id='ivBTa'>

                本文介绍了将复杂字典放入返回队列时,多处理进程不加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                给定一个非常标准的读/写多线程进程,带有一个读队列和一个写队列:

                Given a pretty standard read/write multithreaded process with a read Queue and a write Queue:

                8 次 worker done 被打印,但 join() 语句从未通过.但是,如果我用 `queue_out.put(1) 替换 queue_out.put(r) 它就可以了.

                8 times worker done is printed, but the join() statement is never passed. But if I replace queue_out.put(r) by `queue_out.put(1) it works.

                这正在融化我的大脑,可能是非常愚蠢的事情.我应该复制我的字典并将其放入返回队列吗?我在某个地方犯了一个愚蠢的错误吗?

                This is melting my brain, probably something really stupid. Should I make a copy of my dictionary and put that in the return Queue? Did I make a stupid mistake somewhere?

                处理函数

                def reader(queue_in, queue_out, funktion):
                    # Read from the queue
                    while True:
                        r = queue_in.get()
                        if r == 'DONE':
                            return
                        funktion(r) # funktion adds additional keys to the dictionary
                        queue_out.put(r) # <---- replacing r by 1 does let me join()
                    print "worker done" # <----- this happens
                

                填充输入队列

                def writer(generator, queue):
                    # Write to the queue
                    for r in enumerate(generator):
                        # r is a complex dictionary
                        queue.put(r)    
                    print "writer done"
                    for _ in range(0, WORKERS):
                        queue.put((-1, "DONE"))
                

                其余的

                WORKERS = 8
                
                # init Queues
                queue_in = Queue()
                queue_out = Queue()
                
                # Start processes, with input and output quests
                readers = []
                for _ in range(0, WORKERS):
                    p = Process(target=reader, args=(queue_in, queue_out, funktion))
                    p.daemon = True
                    p.start()
                    readers.append(p)
                
                writer(generator, queue_in)
                
                for p in readers:
                    p.join()
                
                print "joined"  # <---- this never happens
                
                queue_in.close()
                
                while not queue_out.empty():
                    print queue_out.get()
                queue_out.close()
                

                推荐答案

                认为我从两个来源拼凑了这个,因为我总是有同样的问题.我认为重要的是这是在 Windows 中.

                I think I have pieced this together from two sources as I always have the same problem. I think the important thing is that this is in Windows.

                来自文档的注释

                由于 Windows 缺少 os.fork() 它有一些额外的限制:

                Since Windows lacks os.fork() it has a few extra restrictions:

                然后阅读这里的答案join() 用于分叉处理.

                Then read the answers here that join() is for forked processed.

                我一直设法以与您类似的方式运行 multiprocessing 而没有使用 join() 并且没有看到任何错误 - 我很高兴有一个反例解释为什么需要它.事实上,删除它已经解决了您的问题.

                I have always managed to run multiprocessing in a similar fashion to you without using join() and not seen any errors - I'm more than happy for a counterexample to explain why it's needed. Indeed, removing it has corrected your issue.

                这篇文章更深入地探讨了这些差异与操作系统之间的多处理中的子进程.我确实认为 join() 的问题,具体来说,应该在文档中更加明确.

                And this article goes into more depth about the differences with child processes in multiprocessing between operating systems. I do think that the issue with join(), specifically, should be more explicit in the documentation.

                这篇关于将复杂字典放入返回队列时,多处理进程不加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                  <tbody id='HL2Ed'></tbody>
                <tfoot id='HL2Ed'></tfoot>

              • <i id='HL2Ed'><tr id='HL2Ed'><dt id='HL2Ed'><q id='HL2Ed'><span id='HL2Ed'><b id='HL2Ed'><form id='HL2Ed'><ins id='HL2Ed'></ins><ul id='HL2Ed'></ul><sub id='HL2Ed'></sub></form><legend id='HL2Ed'></legend><bdo id='HL2Ed'><pre id='HL2Ed'><center id='HL2Ed'></center></pre></bdo></b><th id='HL2Ed'></th></span></q></dt></tr></i><div id='HL2Ed'><tfoot id='HL2Ed'></tfoot><dl id='HL2Ed'><fieldset id='HL2Ed'></fieldset></dl></div>

                    • <bdo id='HL2Ed'></bdo><ul id='HL2Ed'></ul>

                    • <small id='HL2Ed'></small><noframes id='HL2Ed'>

                        <legend id='HL2Ed'><style id='HL2Ed'><dir id='HL2Ed'><q id='HL2Ed'></q></dir></style></legend>