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

    <small id='qi1tU'></small><noframes id='qi1tU'>

    <tfoot id='qi1tU'></tfoot>

    1. <legend id='qi1tU'><style id='qi1tU'><dir id='qi1tU'><q id='qi1tU'></q></dir></style></legend>

      如何在 python 3 中将队列与并发未来的 ThreadPoolExecutor 一起使用?

      How to use queue with concurrent future ThreadPoolExecutor in python 3?(如何在 python 3 中将队列与并发未来的 ThreadPoolExecutor 一起使用?)
        <i id='Oedv9'><tr id='Oedv9'><dt id='Oedv9'><q id='Oedv9'><span id='Oedv9'><b id='Oedv9'><form id='Oedv9'><ins id='Oedv9'></ins><ul id='Oedv9'></ul><sub id='Oedv9'></sub></form><legend id='Oedv9'></legend><bdo id='Oedv9'><pre id='Oedv9'><center id='Oedv9'></center></pre></bdo></b><th id='Oedv9'></th></span></q></dt></tr></i><div id='Oedv9'><tfoot id='Oedv9'></tfoot><dl id='Oedv9'><fieldset id='Oedv9'></fieldset></dl></div>
          <tbody id='Oedv9'></tbody>

          <tfoot id='Oedv9'></tfoot>
                <bdo id='Oedv9'></bdo><ul id='Oedv9'></ul>

              • <legend id='Oedv9'><style id='Oedv9'><dir id='Oedv9'><q id='Oedv9'></q></dir></style></legend>
              • <small id='Oedv9'></small><noframes id='Oedv9'>

                本文介绍了如何在 python 3 中将队列与并发未来的 ThreadPoolExecutor 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用简单的线程模块来执行并发作业.现在我想利用并发期货模块.有人能给我举一个使用队列和并发库的例子吗?

                I am using simple threading modules to do concurrent jobs. Now I would like to take advantages of concurrent futures modules. Can some put me a example of using a queue with concurrent library?

                我收到 TypeError: 'Queue' object is not iterable我不知道如何迭代队列

                I am getting TypeError: 'Queue' object is not iterable I dont know how to iterate queues

                代码片段:

                 def run(item):
                      self.__log.info(str(item))
                      return True
                <queue filled here>
                
                with concurrent.futures.ThreadPoolExecutor(max_workers = 100) as executor:
                        furtureIteams = { executor.submit(run, item): item for item in list(queue)}
                        for future in concurrent.futures.as_completed(furtureIteams):
                            f = furtureIteams[future]
                            print(f)
                

                推荐答案

                我会建议这样的事情:

                def run(queue):
                      item = queue.get()
                      self.__log.info(str(item))
                      return True
                <queue filled here>
                workerThreadsToStart = 10
                with concurrent.futures.ThreadPoolExecutor(max_workers = 100) as executor:
                        furtureIteams = { executor.submit(run, queue): index for intex in range(workerThreadsToStart)}
                        for future in concurrent.futures.as_completed(furtureIteams):
                            f = furtureIteams[future]
                            print(f)
                

                您将遇到的问题是,队列被认为是无止境的,并且作为一种媒介来解耦将某些内容放入队列的线程和将项目从队列中取出的线程.

                The problem you will run in is that a queue is thought to be endless and as a medium to decouple the threads that put something into the queue and threads that get items out of the queue.

                1. 您的商品数量有限或
                2. 您一次计算所有项目

                然后并行处理它们,队列没有意义.在这些情况下,ThreadPoolExecutor 会使队列过时.

                and afterwards process them in parallel, a queue makes no sense. A ThreadPoolExecutor makes a queue obsolete in these cases.

                我查看了 ThreadPoolExecutor 源代码:

                I had a look at the ThreadPoolExecutor source:

                def submit(self, fn, *args, **kwargs): # line 94
                    self._work_queue.put(w) # line 102
                

                里面使用了一个队列.

                这篇关于如何在 python 3 中将队列与并发未来的 ThreadPoolExecutor 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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='ty4Od'></tbody>
                      <bdo id='ty4Od'></bdo><ul id='ty4Od'></ul>

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

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