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

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

      2. Windows 上的多处理中断

        时间:2023-05-27
          <tbody id='6u5O0'></tbody>
            <bdo id='6u5O0'></bdo><ul id='6u5O0'></ul>

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

              <tfoot id='6u5O0'></tfoot>

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

                  本文介绍了Windows 上的多处理中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在 Linux 上使用 Python 进行开发,但从未真正见过 Windows 出现此类问题.我正在使用 multiprocessing 库来加速计算,这对我在 Linux 上非常有效.

                  I develop with Python on Linux and have never really seen this sort of problem with Windows. I'm using the multiprocessing library to speed up computations, which works very well for me on Linux.

                  然而,在 Windows 上,事情并不顺利:

                  On Windows, however, things don't run as smoothly:

                   * [INFO] Parsing 1 file using 2 threads
                  
                  Traceback (most recent call last):
                    File "main.py", line 170, in <module>
                      master = ParsingMaster(parser, list(input_file), output_list, threads=num_threads)
                  Traceback (most recent call last):
                    File "main.py", line 39, in __init__
                    File "<string>", line 1, in <module>
                      self.input_process.start()
                    File "C:Python26libmultiprocessingforking.py", line 342, in main
                    File "C:Python26libmultiprocessingprocess.py", line 104, in start
                          self._popen = Popen(self)
                  self = load(from_parent)
                    File "C:Python26libmultiprocessingforking.py", line 239, in __init__
                    File "C:Python26libpickle.py", line 1370, in load
                      dump(process_obj, to_child, HIGHEST_PROTOCOL)
                    File "C:Python26libmultiprocessingforking.py", line 162, in dump
                      ForkingPickler(file, protocol).dump(obj)
                    File "C:Python26libpickle.py", line 224, in dump
                      return Unpickler(file).load()
                      self.save(obj)
                   File "C:Python26libpickle.py", line 858, in load
                    File "C:Python26libpickle.py", line 331, in save
                      self.save_reduce(obj=obj, *rv)
                    File "C:Python26libpickle.py", line 419, in save_reduce
                      dispatch[key](self)
                    File "C:Python26libpickle.py", line 880, in load_eof
                      save(state)
                    File "C:Python26libpickle.py", line 286, in save
                      f(self, obj) # Call unbound method with explicit self
                      r aise EOFError
                   File "C:Python26libpickle.py", line 649, in save_dict
                  EOFError
                      self._batch_setitems(obj.iteritems())
                    File "C:Python26libpickle.py", line 681, in _batch_setitems
                      save(v)
                    File "C:Python26libpickle.py", line 286, in save
                      f(self, obj) # Call unbound method with explicit self
                    File "C:Python26libmultiprocessingforking.py", line 40, in dispatcher
                      self.save_reduce(obj=obj, *rv)
                    File "C:Python26libpickle.py", line 401, in save_reduce
                      save(args)
                    File "C:Python26libpickle.py", line 286, in save
                      f(self, obj) # Call unbound method with explicit self
                    File "C:Python26libpickle.py", line 548, in save_tuple
                      save(element)
                    File "C:Python26libpickle.py", line 331, in save
                      self.save_reduce(obj=obj, *rv)
                    File "C:Python26libpickle.py", line 419, in save_reduce
                      save(state)
                    File "C:Python26libpickle.py", line 286, in save
                      f(self, obj) # Call unbound method with explicit self
                    File "C:Python26libpickle.py", line 649, in save_dict
                      self._batch_setitems(obj.iteritems())
                    File "C:Python26libpickle.py", line 681, in _batch_setitems
                      save(v)
                    File "C:Python26libpickle.py", line 306, in save
                      rv = reduce(self.proto)
                    File "C:Python26libmultiprocessingmanagers.py", line 458, in __reduce__
                      return type(self).from_address, 
                  AttributeError: type object 'SyncManager' has no attribute 'from_address'
                  

                  我正在 Windows 7 上同时测试 Python 2.6 和 2.7,并且一遍又一遍地遇到同样的错误.有人知道是什么意思吗?

                  I'm testing on both Python 2.6 and 2.7 on Windows 7 and get this same error over and over. Does anybody know what it means?

                  推荐答案

                  Windows有限制,这里是你看到的错误的相关部分:

                  There are restrictions on Windows, here is the relevant parts to the errors you are seeing:

                  由于 Windows 缺少 os.fork() 它有一些额外的限制:

                  更易腌制

                  确保 Process.__init__() 的所有参数都是可挑选的.这尤其意味着不能使用绑定或未绑定的方法直接作为 Windows 上的目标参数 - 只需定义一个函数并改用它.

                  Ensure that all arguments to Process.__init__() are picklable. This means, in particular, that bound or unbound methods cannot be used directly as the target argument on Windows — just define a function and use that instead.

                  此外,如果您将 Process 子类化,请确保实例是调用 Process.start() 方法时可挑选.

                  Also, if you subclass Process then make sure that instances will be picklable when the Process.start() method is called.

                  这意味着作为参数传递给 Process.__init__() 不能被腌制或解封(Python中的序列化).什么是 SyncManager 它抱怨无法在该对象上找到属性 AttributeError: type object 'SyncManager' has no attribute 'from_address',这可能是你的根本原因.SyncManager 对象真的可以腌制吗,是否符合pickle规则?

                  This means that something that is being passed as an argument to Process.__init__() isn't able to be pickled or unpickled ( a serialization in Python ). What is SyncManager it is complaining about not being able to find attributes on that object AttributeError: type object 'SyncManager' has no attribute 'from_address', it is probably your root cause. Can that SyncManager object actually be pickled, does it meet the pickle rules?

                  如果您是从 Windows 上的 命令行运行它,您显然也不能这样做.

                  If you are running this from the command line on Windows, you can't do that either apparently.

                  不要那样做.将代码保存在文件中,然后使用以下命令从文件中运行它:

                  Don't do that. Save the code in a file and run it from the file instead, with the command:

                  python myfile.py
                  

                  这将解决您的问题.

                  这篇关于Windows 上的多处理中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将生成器用作具有多处理映射功能的可迭代 下一篇:多处理和莳萝可以一起做什么?

                  相关文章

                  最新文章

                  <legend id='1HTWQ'><style id='1HTWQ'><dir id='1HTWQ'><q id='1HTWQ'></q></dir></style></legend>

                      <tfoot id='1HTWQ'></tfoot>

                      <small id='1HTWQ'></small><noframes id='1HTWQ'>

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