• <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 中使用队列

        时间:2023-09-29
          <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 中使用队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在没有线程或任务队列的情况下在 Flask 中运行后台作业 下一篇:在 Python 线程/队列方面需要一些帮助

                  相关文章

                  1. <tfoot id='IVvj9'></tfoot>

                    • <bdo id='IVvj9'></bdo><ul id='IVvj9'></ul>
                  2. <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'>