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

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

      <tfoot id='iJhu0'></tfoot>

      1. <legend id='iJhu0'><style id='iJhu0'><dir id='iJhu0'><q id='iJhu0'></q></dir></style></legend>

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

        Process.run() 和 Process.start() 之间的区别

        时间:2023-05-26
          <bdo id='vSjNr'></bdo><ul id='vSjNr'></ul>
            <legend id='vSjNr'><style id='vSjNr'><dir id='vSjNr'><q id='vSjNr'></q></dir></style></legend>

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

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

                  <tbody id='vSjNr'></tbody>

                  本文介绍了Process.run() 和 Process.start() 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我很难理解 run()start() 之间的区别.根据文档, run() 方法调用传递给对象构造函数的可调用对象,而 start() 方法启动进程并且只能调用一次.

                  I am struggling to understand the difference between run() and start(). According to the documentation, run() method invokes the callable object passed to the object's constructor, while start() method starts the process and can be called only once.

                  我尝试了以下示例:

                  def get_process_id(process_name):
                      print process_name, os.getpid()
                  
                  p1 = multiprocessing.Process(target=get_process_id, args=('process_1',))
                  p2 = multiprocessing.Process(target=get_process_id, args=('process_2',))
                  
                  p1.run()
                  p2.run()
                  p1.start()
                  p2.start()
                  

                  结果如下:

                  process_1 35138
                  process_2 35138
                  process_1 35141
                  process_2 35142
                  

                  当我使用 run() 时,它表明 p1p2 使用相同的过程.但是当我使用 start() 时,他们给出了两个不同的.是不是因为调用 run() 与调用它的进程没有任何关系,只是调用函数(本例中为 get_process_id)?p>

                  When I use run(), it shows that p1 and p2 uses the same process. But when I use start(), they give the two difference ones. Is it because calling run() doesn't have anything to do with the process that calls it but just calling the function (which is get_process_id in this example)?

                  推荐答案

                  你不应该显式调用 process.run().它是调用您指定的 target 函数的方法,除非您在子类化 Process 时重写它.它通常在引导时在新子代中被调用.它除了调用目标函数之外什么都不做.

                  You are not supposed to call process.run() explicitly. It's the method which invokes your specified target function unless you override it when you subclass Process. It normally gets called within the new child while it bootstraps. It does nothing else than calling the target function.

                  # multiprocessing.process.BaseProcess
                  
                  def run(self):
                      '''
                      Method to be run in sub-process; can be overridden in sub-class
                      '''
                      if self._target:
                          self._target(*self._args, **self._kwargs)
                  

                  当您在父进程中调用它时,它会像任何其他方法一样在您的父进程中执行.

                  When you call it in your parent process, it gets executed in your parent process like any other method.

                  process.start() 是您应该首先在父进程中调用以创建新进程的方法.

                  process.start() is the method which you're supposed to call in your parent to create the new process in the first place.

                  这篇关于Process.run() 和 Process.start() 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在多个线程中运行`selenium-chromedriver` 下一篇:是否可以从 Scrapy spider 运行另一个蜘蛛?

                  相关文章

                  最新文章

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

                  1. <legend id='Ol1tA'><style id='Ol1tA'><dir id='Ol1tA'><q id='Ol1tA'></q></dir></style></legend>

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