久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

        故意在python中創(chuàng)建一個(gè)孤兒進(jìn)程

        Deliberately make an orphan process in python(故意在python中創(chuàng)建一個(gè)孤兒進(jìn)程)

        <i id='C9qFB'><tr id='C9qFB'><dt id='C9qFB'><q id='C9qFB'><span id='C9qFB'><b id='C9qFB'><form id='C9qFB'><ins id='C9qFB'></ins><ul id='C9qFB'></ul><sub id='C9qFB'></sub></form><legend id='C9qFB'></legend><bdo id='C9qFB'><pre id='C9qFB'><center id='C9qFB'></center></pre></bdo></b><th id='C9qFB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='C9qFB'><tfoot id='C9qFB'></tfoot><dl id='C9qFB'><fieldset id='C9qFB'></fieldset></dl></div>
      1. <small id='C9qFB'></small><noframes id='C9qFB'>

        1. <tfoot id='C9qFB'></tfoot>
        2. <legend id='C9qFB'><style id='C9qFB'><dir id='C9qFB'><q id='C9qFB'></q></dir></style></legend>

              <tbody id='C9qFB'></tbody>

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

                  本文介紹了故意在python中創(chuàng)建一個(gè)孤兒進(jìn)程的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我有一個(gè)名為 MyScript 的 Python 腳本(類似于 unix,基于 RHEL),它有兩個(gè)函數(shù),分別稱為 A 和 B.我希望它們?cè)诓煌莫?dú)立進(jìn)程中運(yùn)行(分離 B 和 A):

                  I have a python script (unix-like, based on RHEL), called MyScript, that has two functions, called A and B. I'd like them to run in different, independent processes (detach B and A):

                  • 啟動(dòng)腳本 MyScript
                  • 執(zhí)行函數(shù)A
                  • 生成一個(gè)新進(jìn)程,將數(shù)據(jù)從函數(shù) A 傳遞到 B
                  • 當(dāng)函數(shù) B 運(yùn)行時(shí),繼續(xù)函數(shù) A
                  • 當(dāng)函數(shù) A 完成時(shí),即使 B 仍在運(yùn)行,也要退出 MyScript

                  我認(rèn)為我應(yīng)該使用多處理來創(chuàng)建一個(gè)守護(hù)進(jìn)程,但是 documentation 表明這不是正確的用例.所以,我決定生成一個(gè)子進(jìn)程和 child^2 進(jìn)程(孩子的孩子),然后強(qiáng)制孩子終止.雖然這種解決方法似乎有效,但看起來真的很難看.

                  I thought I should use multiprocessing to create a daemon process, but the documentation suggests that's not the right usecase. So, I decided to spawn a child process and child^2 process (the child's child), and then force the child to terminate. While this workaround appears to work, it seems really ugly.

                  你能幫我讓它更 Pythonic 嗎?subprocess 模塊是否有可以對(duì)函數(shù)進(jìn)行操作的方法?示例代碼如下.

                  Can you help me make it more pythonic? Does the subprocess module have a method that will operate on a function? Sample code below.

                  import multiprocessing
                  import time
                  import sys
                  import os
                  
                  def parent_child():
                      p = multiprocessing.current_process()
                      print 'Starting parent child:', p.name, p.pid
                      sys.stdout.flush()
                      cc = multiprocessing.Process(name='childchild', target=child_child)
                      cc.daemon = False
                      cc.start()
                      print 'Exiting parent child:', p.name, p.pid
                      sys.stdout.flush()
                  
                  def child_child():
                      p = multiprocessing.current_process()
                      print 'Starting child child:', p.name, p.pid
                      sys.stdout.flush()
                      time.sleep(30)
                      print 'Exiting child child:', p.name, p.pid
                      sys.stdout.flush()
                  
                  def main():
                      print 'starting main', os.getpid()
                      d = multiprocessing.Process(name='parentchild', target=parent_child)
                      d.daemon = False
                      d.start()
                      time.sleep(5)
                      d.terminate()
                      print 'exiting main', os.getpid()
                  
                  main()
                  

                  推薦答案

                  這只是原始代碼的隨機(jī)版本,它將功能移動(dòng)到單個(gè)調(diào)用 spawn_detached(callable).即使在程序退出后,它也會(huì)保持分離的進(jìn)程運(yùn)行:

                  Here is just a random version of your original code that moves the functionality into a single call spawn_detached(callable). It keeps the detached process running even after the program exits:

                  import time
                  import os
                  from multiprocessing import Process, current_process
                  
                  def spawn_detached(callable):
                      p = _spawn_detached(0, callable)
                      # give the process a moment to set up
                      # and then kill the first child to detach
                      # the second.
                      time.sleep(.001)
                      p.terminate()
                  
                  def _spawn_detached(count, callable):
                      count += 1
                      p = current_process()
                      print 'Process #%d: %s (%d)' % (count, p.name, p.pid)
                  
                      if count < 2:
                          name = 'child'
                      elif count == 2:
                          name = callable.func_name
                      else:
                          # we should now be inside of our detached process
                          # so just call the function
                          return callable()
                  
                      # otherwise, spawn another process, passing the counter as well
                      p = Process(name=name, target=_spawn_detached, args=(count, callable)) 
                      p.daemon = False 
                      p.start()
                      return p
                  
                  def operation():
                      """ Just some arbitrary function """
                      print "Entered detached process"
                      time.sleep(15)
                      print "Exiting detached process"
                  
                  
                  if __name__ == "__main__":
                      print 'starting main', os.getpid()
                      p = spawn_detached(operation)
                      print 'exiting main', os.getpid()
                  

                  這篇關(guān)于故意在python中創(chuàng)建一個(gè)孤兒進(jìn)程的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個(gè)參數(shù)傳遞給 pool.map() 函數(shù))
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進(jìn)程池.當(dāng)其中一個(gè)工作進(jìn)程確定不再需要完成工作時(shí),如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯(cuò)誤的另一個(gè)混淆,“模塊對(duì)象沒有屬性“f)

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

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

                        <legend id='WbUAC'><style id='WbUAC'><dir id='WbUAC'><q id='WbUAC'></q></dir></style></legend>
                          <tbody id='WbUAC'></tbody>
                        <tfoot id='WbUAC'></tfoot>

                            主站蜘蛛池模板: 精品视频一区在线 | 日韩欧美精品在线 | 在线播放一区二区三区 | 一级毛片免费 | 男人阁久久| 国产成人精品久久二区二区91 | 国产成人网 | 日韩在线视频免费观看 | 日韩一区二区在线视频 | 日本久久久久久 | 亚洲精品日韩精品 | 国产永久免费 | 天天插日日操 | 久久成人人人人精品欧 | 国产99久久精品一区二区300 | 日韩国产在线 | 在线国产小视频 | 在线成人免费观看 | 精品免费国产一区二区三区四区 | 视频一区二区在线 | 国产精彩视频一区 | 成人精品一区亚洲午夜久久久 | 四虎成人免费视频 | 一区二区久久精品 | 国产高清av免费观看 | 久久久久久国产精品免费免费 | 国产在线播放av | 欧美video| 国产精品射 | 午夜小影院 | 免费天天干 | 久久精品一区二区三区四区 | 欧美a级成人淫片免费看 | 国产麻豆一区二区三区 | 精品一区av | 久久高清| 综合五月| 韩日在线 | 91天堂网| 亚洲精品久久久久久久不卡四虎 | 91免费在线看 |