• <small id='7IA2f'></small><noframes id='7IA2f'>

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

        在 python 中使用队列

        Using Queue in python(在 python 中使用队列)
          <bdo id='LhwCD'></bdo><ul id='LhwCD'></ul>

            <tbody id='LhwCD'></tbody>

                <tfoot id='LhwCD'></tfoot>

              1. <small id='LhwCD'></small><noframes id='LhwCD'>

                  <legend id='LhwCD'><style id='LhwCD'><dir id='LhwCD'><q id='LhwCD'></q></dir></style></legend>
                • <i id='LhwCD'><tr id='LhwCD'><dt id='LhwCD'><q id='LhwCD'><span id='LhwCD'><b id='LhwCD'><form id='LhwCD'><ins id='LhwCD'></ins><ul id='LhwCD'></ul><sub id='LhwCD'></sub></form><legend id='LhwCD'></legend><bdo id='LhwCD'><pre id='LhwCD'><center id='LhwCD'></center></pre></bdo></b><th id='LhwCD'></th></span></q></dt></tr></i><div id='LhwCD'><tfoot id='LhwCD'></tfoot><dl id='LhwCD'><fieldset id='LhwCD'></fieldset></dl></div>
                  本文介绍了在 python 中使用队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Eclipse(使用 PyDev)中运行以下命令,但我不断收到错误消息:

                  q = queue.Queue(maxsize=0)NameError:未定义全局名称队列"

                  我已经检查了文档,看起来应该是这样放置的.我在这里错过了什么吗?PyDev 是这样工作的吗?或在代码中遗漏了什么?感谢大家的帮助.

                  从队列导入 *定义工人():而真:项目 = q.get()做工作(项目)q.task_done()定义主():q = queue.Queue(maxsize=0)对于我在范围内(num_worker_threads):t = 线程(目标 = 工人)t.daemon = 真t.start()对于 source() 中的项目:q.put(项目)q.join() # 阻塞直到所有任务完成主要的()

                  使用:Eclipse SDK

                  版本:3.8.1内部版本号:M20120914-1540

                  和 Python 3.3

                  解决方案

                  你做

                  从队列导入 *

                  这已经从 queue 模块中导入了所有类.将该行更改为

                  q = 队列(maxsize=0)

                  <块引用>

                  小心:应避免通配符导入(来自 import *),因为它们使命名空间中存在哪些名称变得不清楚,从而使读者和许多自动化工具感到困惑".(Python PEP-8)

                  作为一种替代方法,可以使用:

                  从队列导入队列q = 队列(最大尺寸=0)

                  I'm trying to run the following in Eclipse (using PyDev) and I keep getting error :

                  q = queue.Queue(maxsize=0) NameError: global name 'queue' is not defined

                  I've checked the documentations and appears that is how its supposed to be placed. Am I missing something here? Is it how PyDev works? or missing something in the code? Thanks for all help.

                  from queue import *
                  
                  def worker():
                      while True:
                          item = q.get()
                          do_work(item)
                          q.task_done()
                  
                  def main():
                  
                      q = queue.Queue(maxsize=0)
                      for i in range(num_worker_threads):
                           t = Thread(target=worker)
                           t.daemon = True
                           t.start()
                  
                      for item in source():
                          q.put(item)
                  
                      q.join()       # block until all tasks are done
                  
                  main()
                  

                  Using: Eclipse SDK

                  Version: 3.8.1 Build id: M20120914-1540

                  and Python 3.3

                  解决方案

                  You do

                  from queue import *
                  

                  This imports all the classes from the queue module already. Change that line to

                  q = Queue(maxsize=0)
                  

                  CAREFUL: "Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools". (Python PEP-8)

                  As an alternative, one could use:

                  from queue import Queue
                  
                  q = Queue(maxsize=0)
                  

                  这篇关于在 python 中使用队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据框制作线图?)
                  1. <tfoot id='IVvj9'></tfoot>

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

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

                              <tbody id='IVvj9'></tbody>