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

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

    1. <legend id='aUDp6'><style id='aUDp6'><dir id='aUDp6'><q id='aUDp6'></q></dir></style></legend>
    2. <small id='aUDp6'></small><noframes id='aUDp6'>

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

        有沒有辦法將'stdin'作為參數(shù)傳遞給python中

        Is there any way to pass #39;stdin#39; as an argument to another process in python?(有沒有辦法將stdin作為參數(shù)傳遞給python中的另一個(gè)進(jìn)程?)

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

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

                  <tbody id='Z7Ar7'></tbody>

                  本文介紹了有沒有辦法將'stdin'作為參數(shù)傳遞給python中的另一個(gè)進(jìn)程?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  我正在嘗試創(chuàng)建一個(gè)使用 python 的多處理模塊的腳本.該腳本(我們稱之為 myscript.py)將從另一個(gè)帶有管道的腳本中獲取輸入.

                  I'm trying to create a script which is using multiprocessing module with python. The script (lets call it myscript.py) will get the input from another script with pipe.

                  假設(shè)我這樣調(diào)用腳本;

                  $ python writer.py | python myscript.py 
                  

                  這里是代碼;

                  // writer.py
                  import time, sys
                  
                  def main():
                      while True:
                          print "test"
                          sys.stdout.flush()
                          time.sleep(1)
                  
                  main()
                  
                  //myscript.py
                  def get_input():
                      while True:
                          text = sys.stdin.readline()
                          print "hello " + text
                          time.sleep(3)
                  
                  if __name__ == '__main__':        
                      p1 = Process(target=get_input, args=())
                      p1.start()
                  

                  這顯然不起作用,因?yàn)橹鬟M(jìn)程和 p1 的 sys.stdin 對(duì)象不同.所以我嘗試了這個(gè)來解決它,

                  this is clearly not working, since the sys.stdin objects are different for main process and p1. So I have tried this to solve it,

                  //myscript.py
                  def get_input(temp):
                      while True:
                          text = temp.readline()
                          print "hello " + text
                          time.sleep(3)
                  
                  if __name__ == '__main__':        
                      p1 = Process(target=get_input, args=(sys.stdin,))
                      p1.start()
                  

                  但是我遇到了這個(gè)錯(cuò)誤;

                  but I come across with this error;

                  Process Process-1:
                  Traceback (most recent call last):
                    File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
                      self.run()
                    File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
                      self._target(*self._args, **self._kwargs)
                    File "in.py", line 12, in get_input
                      text = temp.readline()
                  ValueError: I/O operation on closed file
                  

                  所以,我猜 main 的 stdin 文件已關(guān)閉,我無法從中讀取.在這個(gè)結(jié)合處,我如何將 main 的 stdin 文件傳遞??給另一個(gè)進(jìn)程?如果無法通過標(biāo)準(zhǔn)輸入,我該如何使用來自另一個(gè)進(jìn)程的 main 標(biāo)準(zhǔn)輸入?

                  So, I guess that main's stdin file closed and I can't read from it. At this conjunction, how can I pass main's stdin file to another process? If passing stdin is not possible, how can I use main's stdin from another process?

                  更新:好的,我需要澄清我的問題,因?yàn)槿藗冋J(rèn)為使用多處理并不是真正必要的.像這樣考慮 myscript.py;

                  update: Okay, I need to clarify my question since people think using multiprocessing is not really necessary. consider myscript.py like this;

                  //myscript.py
                  def get_input():
                      while True:
                          text = sys.stdin.readline()
                          print "hello " + text
                          time.sleep(3)
                  
                  def do_more_things():
                      while True:
                          #// some code here
                          time.sleep(60*5)
                  
                  if __name__ == '__main__':        
                      p1 = Process(target=get_input, args=())
                      p1.start()
                  
                      do_more_things()
                  

                  所以,我真的需要將 get_input() 函數(shù)與 main 函數(shù)(或其他子進(jìn)程)并行運(yùn)行.很抱歉發(fā)生沖突,我的英語不錯(cuò),我想我對(duì)這個(gè)問題不太清楚.如果你們能告訴我我是否可以在另一個(gè)進(jìn)程中使用主進(jìn)程 STDIN 對(duì)象,我將不勝感激.

                  so, I really need to run get_input() function parallelly with main function (or other sub processes). Sorry for the conflicts, I have a decent English, and I guess I couldn't be clear on this question. I would appreciate if you guys can tell me if i can use the main processes STDIN object in another process.

                  提前致謝.

                  推薦答案

                  最簡(jiǎn)單的就是交換get_input()do_more_things(),即讀取sys.stdin 在父進(jìn)程中:

                  The simplest thing is to swap get_input() and do_more_things() i.e., read sys.stdin in the parent process:

                  def get_input(stdin):
                      for line in iter(stdin.readline, ''):
                          print("hello", line, end='')
                      stdin.close()
                  
                  if __name__ == '__main__':
                      p1 = mp.Process(target=do_more_things)
                      p1.start()
                      get_input(sys.stdin)
                  

                  下一個(gè)最好的方法是在 get_input() 中使用 Thread() 而不是 Process():

                  The next best thing is to use a Thread() instead of a Process() for get_input():

                  if __name__ == '__main__':
                      t = Thread(target=get_input, args=(sys.stdin,))
                      t.start()
                      do_more_things()
                  

                  如果上述方法沒有幫助你可以嘗試 os.dup():

                  If the above doesn't help you could try os.dup():

                  newstdin = os.fdopen(os.dup(sys.stdin.fileno()))
                  try: 
                     p = Process(target=get_input, args=(newstdin,))
                     p.start()    
                  finally:
                     newstdin.close() # close in the parent
                  do_more_things()
                  

                  這篇關(guān)于有沒有辦法將'stdin'作為參數(shù)傳遞給python中的另一個(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='FL3hn'><tr id='FL3hn'><dt id='FL3hn'><q id='FL3hn'><span id='FL3hn'><b id='FL3hn'><form id='FL3hn'><ins id='FL3hn'></ins><ul id='FL3hn'></ul><sub id='FL3hn'></sub></form><legend id='FL3hn'></legend><bdo id='FL3hn'><pre id='FL3hn'><center id='FL3hn'></center></pre></bdo></b><th id='FL3hn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FL3hn'><tfoot id='FL3hn'></tfoot><dl id='FL3hn'><fieldset id='FL3hn'></fieldset></dl></div>

                        <bdo id='FL3hn'></bdo><ul id='FL3hn'></ul>
                            <tbody id='FL3hn'></tbody>
                          <legend id='FL3hn'><style id='FL3hn'><dir id='FL3hn'><q id='FL3hn'></q></dir></style></legend>
                        1. <tfoot id='FL3hn'></tfoot>

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

                            主站蜘蛛池模板: 国产精品久久久久久久久久久久久久 | 久久精品日产第一区二区三区 | 日韩欧美在线观看视频 | 国产精品久久久久久久久久久久冷 | aa级毛片毛片免费观看久 | 久久久国产一区二区三区 | 精品成人佐山爱一区二区 | 亚洲三区在线观看 | 三级成人片 | 天天影视网天天综合色在线播放 | 国外成人在线视频网站 | 欧洲一级毛片 | 风间由美一区二区三区在线观看 | 日本三级精品 | 欧美一区二区三区久久精品 | 久久精品国产99国产精品 | 密室大逃脱第六季大神版在线观看 | 成人av片在线观看 | 91视频91| 日韩视频a | 久久久久久久电影 | 中文字幕一区二区三区在线观看 | 欧美另类视频在线 | 国产三区视频在线观看 | 国产东北一级毛片 | av在线免费观看网站 | 中文字幕二区 | 久草成人 | 亚洲精品一区二区冲田杏梨 | 久久精品综合 | 欧美精品一区二区三区四区 在线 | 欧美一级网站 | 特级特黄特色的免费大片 | 久久精品91久久久久久再现 | 国产美女一区二区三区 | 中文字幕第5页 | 久久骚| 亚洲人成在线播放 | 自拍偷拍第一页 | 日本高清aⅴ毛片免费 | 黄网站免费观看 |