<bdo id='sMpNV'></bdo><ul id='sMpNV'></ul>

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

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

      3. python多处理管理器列表错误:[Errno 2]没有这样的文

        时间:2023-05-26

          <legend id='tfvyl'><style id='tfvyl'><dir id='tfvyl'><q id='tfvyl'></q></dir></style></legend>

        1. <tfoot id='tfvyl'></tfoot>
          1. <small id='tfvyl'></small><noframes id='tfvyl'>

            <i id='tfvyl'><tr id='tfvyl'><dt id='tfvyl'><q id='tfvyl'><span id='tfvyl'><b id='tfvyl'><form id='tfvyl'><ins id='tfvyl'></ins><ul id='tfvyl'></ul><sub id='tfvyl'></sub></form><legend id='tfvyl'></legend><bdo id='tfvyl'><pre id='tfvyl'><center id='tfvyl'></center></pre></bdo></b><th id='tfvyl'></th></span></q></dt></tr></i><div id='tfvyl'><tfoot id='tfvyl'></tfoot><dl id='tfvyl'><fieldset id='tfvyl'></fieldset></dl></div>
                <tbody id='tfvyl'></tbody>
                • <bdo id='tfvyl'></bdo><ul id='tfvyl'></ul>
                  本文介绍了python多处理管理器列表错误:[Errno 2]没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在 python 中编写了一个多处理程序.我使用 multiprocessing.Manager().list() 在子进程中共享列表.首先,我在主流程中添加了一些任务.然后,启动一些子进程来执行共享列表中的任务,子进程也将任务添加到共享列表中.但我得到了一个例外:

                  I worte a multiprocessing program in python. I use multiprocessing.Manager().list() to share list within subprocess. At first, I add some tasks in main process. And then, start some subprocesses to do tasks which in the shared list, the subprocesses also add tasks to the shared list. But I got a exception as follow:

                      Traceback (most recent call last):
                        File "/usr/lib64/python2.6/multiprocessing/process.py", line 232, in _bootstrap
                          self.run()
                        File "/usr/lib64/python2.6/multiprocessing/process.py", line 88, in run
                          self._target(*self._args, **self._kwargs)
                        File "gen_friendship.py", line 255, in worker
                          if tmpu in nodes:
                        File "<string>", line 2, in __contains__
                        File "/usr/lib64/python2.6/multiprocessing/managers.py", line 722, in _callmethod
                          self._connect()
                        File "/usr/lib64/python2.6/multiprocessing/managers.py", line 709, in _connect
                          conn = self._Client(self._token.address, authkey=self._authkey)
                        File "/usr/lib64/python2.6/multiprocessing/connection.py", line 143, in Client
                          c = SocketClient(address)
                        File "/usr/lib64/python2.6/multiprocessing/connection.py", line 263, in SocketClient
                          s.connect(address)
                        File "<string>", line 1, in connect
                      error: [Errno 2] No such file or directory
                  

                  我发现了一些关于如何在 python 多处理中使用共享列表的信息,例如 这个.但还是有一些例外.我不知道异常的含义.而common list和manager.list有什么区别?

                  I find something about how to use shared list in python multiprocessing like this. But still have some exception. I have no idea of the meaning of the exception. And what's the difference between the common list and the manager.list?

                  代码如下:

                      nodes = multiprocessing.Manager().list()
                  
                      lock = multiprocessing.Lock()
                  
                      AMOUNT_OF_PROCESS = 10
                  
                      def worker():
                          lock.acquire()
                          nodes.append(node)
                          lock.release()
                  
                      if __name__ == "__main__":
                  
                          for i in range(i):
                              nodes.append({"name":"username", "group":1})
                  
                          processes = [None for i in range(AMOUNT_OF_PROCESS)]
                  
                          for i in range(AMOUNT_OF_PROCESS):
                              processes[i] = multiprocessing.Process(taget=worker, args=())
                              processes[i].start()
                  

                  推荐答案

                  问题是你的主进程在你启动所有工作进程后立即退出,这会关闭你的 Manager.当您的 Manager 关闭时,没有一个孩子可以使用您传递给他们的共享列表.您可以通过使用 join 等待所有孩子完成来修复它.只需确保在调用 join 之前确实 start 所有进程:

                  The problem is that your main process is exiting immediately after you start all your worker processes, which shuts down your Manager. When your Manager shuts down, none of the children can use the shared list you passed into them. You can fix it by using join to wait for all the children to finish. Just make sure you actually start all your processes prior to calling join:

                  for i in range(AMOUNT_OF_PROCESS):
                      processes[i] = multiprocessing.Process(target=worker, args=())
                      processes[i].start()
                  for process in processes:
                      process.join()
                  

                  这篇关于python多处理管理器列表错误:[Errno 2]没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么 numpy 计算不受全局解释器锁的影响? 下一篇:在python中控制用于调用外部命令的子进程数

                  相关文章

                  最新文章

                    <tfoot id='IoKbV'></tfoot>

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

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

                    1. <legend id='IoKbV'><style id='IoKbV'><dir id='IoKbV'><q id='IoKbV'></q></dir></style></legend>
                      • <bdo id='IoKbV'></bdo><ul id='IoKbV'></ul>