• <tfoot id='hUzV2'></tfoot>
      <bdo id='hUzV2'></bdo><ul id='hUzV2'></ul>

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

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

        Python多处理错误:AttributeError:模块'__main__'没

        时间:2023-05-26
      1. <i id='gMHmq'><tr id='gMHmq'><dt id='gMHmq'><q id='gMHmq'><span id='gMHmq'><b id='gMHmq'><form id='gMHmq'><ins id='gMHmq'></ins><ul id='gMHmq'></ul><sub id='gMHmq'></sub></form><legend id='gMHmq'></legend><bdo id='gMHmq'><pre id='gMHmq'><center id='gMHmq'></center></pre></bdo></b><th id='gMHmq'></th></span></q></dt></tr></i><div id='gMHmq'><tfoot id='gMHmq'></tfoot><dl id='gMHmq'><fieldset id='gMHmq'></fieldset></dl></div>
            <tbody id='gMHmq'></tbody>

            <bdo id='gMHmq'></bdo><ul id='gMHmq'></ul>
          • <legend id='gMHmq'><style id='gMHmq'><dir id='gMHmq'><q id='gMHmq'></q></dir></style></legend>

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

                <tfoot id='gMHmq'></tfoot>
                  本文介绍了Python多处理错误:AttributeError:模块'__main__'没有属性'__spec__'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在使用 Python 3.6,并尝试遵循下面网站上的第一个示例(完整代码也在下面)并且收到以下错误:https://docs.python.org/3.6/library/multiprocessing.html

                  I'm using Python 3.6 and am trying to follow along with the very first example at the website below (full code also below) and am getting the below error: https://docs.python.org/3.6/library/multiprocessing.html

                  错误信息:AttributeError: 模块 '__main__' 没有属性 '__spec__'

                  完整示例代码:

                  from multiprocessing import Pool
                  
                  def f(x):
                      return x*x
                  
                  if __name__ == '__main__':
                      with Pool(5) as p:
                          print(p.map(f, [1, 2, 3]))
                  

                  我尝试用谷歌搜索它并搜索 Stack Overflow,但我只发现了另一种这种错误的情况,它没有答案.

                  I tried Googling it and searching Stack Overflow but I've only found one other case of this error and it did not have an answer.

                  推荐答案

                  问题不在于代码/Python 3.6,而在于 Spyder.

                  The problem is not with the code / Python 3.6, it is with Spyder.

                  经过一番调查,我发现代码在外部系统终端中执行时运行良好,但在 Spyder 的 IPython 控制台中运行时却不行.

                  After some investigation I found that the code runs fine when executed in an external system terminal but not when run in Spyder's IPython console.

                  我能够转储 spec 的内容并将它们分配给包含在 ma​​in 中的变量,以允许此代码在 IPython 控制台中运行.

                  I was able to dump the contents of spec and assign them to a variable that was included inside main to allow this code to function within the IPython console.

                  from multiprocessing import Pool
                  
                  def f(x):
                      return x*x
                  
                  if __name__ == '__main__':
                      __spec__ = "ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>)"
                      with Pool(5) as p:
                         print (p.map(f, [1, 2, 3]))
                  

                  这篇关于Python多处理错误:AttributeError:模块'__main__'没有属性'__spec__'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为进程指定特定的 CPU - python 多处理 下一篇:对每个进程使用具有不同随机种子的 python 多处理

                  相关文章

                  最新文章

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

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