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

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

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

  • <legend id='XDHh6'><style id='XDHh6'><dir id='XDHh6'><q id='XDHh6'></q></dir></style></legend>

        <tfoot id='XDHh6'></tfoot>

        与多处理错误的另一个混淆,“模块"对象没

        时间:2023-05-27

                <tbody id='AedKU'></tbody>
              <legend id='AedKU'><style id='AedKU'><dir id='AedKU'><q id='AedKU'></q></dir></style></legend>

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

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

                • <i id='AedKU'><tr id='AedKU'><dt id='AedKU'><q id='AedKU'><span id='AedKU'><b id='AedKU'><form id='AedKU'><ins id='AedKU'></ins><ul id='AedKU'></ul><sub id='AedKU'></sub></form><legend id='AedKU'></legend><bdo id='AedKU'><pre id='AedKU'><center id='AedKU'></center></pre></bdo></b><th id='AedKU'></th></span></q></dt></tr></i><div id='AedKU'><tfoot id='AedKU'></tfoot><dl id='AedKU'><fieldset id='AedKU'></fieldset></dl></div>
                • <tfoot id='AedKU'></tfoot>
                  本文介绍了与多处理错误的另一个混淆,“模块"对象没有属性“f"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我知道这个问题之前已经回答过了,但似乎直接执行脚本python filename.py"是行不通的.我在 SuSE Linux 上安装了 Python 2.6.2.

                  I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.

                  代码:

                  #!/usr/bin/python
                  # -*- coding: utf-8 -*-
                  from multiprocessing import Pool
                  p = Pool(1)
                  def f(x):
                      return x*x
                  p.map(f, [1, 2, 3])
                  

                  命令行:

                  > python example.py
                  Process PoolWorker-1:
                  Traceback (most recent call last):
                  File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
                      self.run()
                  File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
                      self._target(*self._args, **self._kwargs)
                  File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
                      task = get()
                  File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
                      return recv()
                  AttributeError: 'module' object has no attribute 'f'
                  

                  推荐答案

                  重构代码,以便在创建 Pool 实例之前定义 f() 函数.否则worker看不到你的函数.

                  Restructure your code so that the f() function is defined before you create instance of Pool. Otherwise the worker cannot see your function.

                  #!/usr/bin/python
                  # -*- coding: utf-8 -*-
                  
                  from multiprocessing import Pool
                  
                  def f(x):
                      return x*x
                  
                  p = Pool(1)
                  p.map(f, [1, 2, 3])
                  

                  这篇关于与多处理错误的另一个混淆,“模块"对象没有属性“f"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:多处理:使用 tqdm 显示进度条 下一篇:如何将队列引用传递给 pool.map_async() 管理的函数

                  相关文章

                  最新文章

                • <legend id='XFv4P'><style id='XFv4P'><dir id='XFv4P'><q id='XFv4P'></q></dir></style></legend>

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

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

                    <tfoot id='XFv4P'></tfoot>