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

        <tfoot id='CyTTA'></tfoot>
        <legend id='CyTTA'><style id='CyTTA'><dir id='CyTTA'><q id='CyTTA'></q></dir></style></legend>
        • <bdo id='CyTTA'></bdo><ul id='CyTTA'></ul>

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

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

        將 asyncio 與多處理結(jié)合起來會(huì)出現(xiàn)什么樣的問題

        What kind of problems (if any) would there be combining asyncio with multiprocessing?(將 asyncio 與多處理結(jié)合起來會(huì)出現(xiàn)什么樣的問題(如果有的話)?)
        <i id='egmUN'><tr id='egmUN'><dt id='egmUN'><q id='egmUN'><span id='egmUN'><b id='egmUN'><form id='egmUN'><ins id='egmUN'></ins><ul id='egmUN'></ul><sub id='egmUN'></sub></form><legend id='egmUN'></legend><bdo id='egmUN'><pre id='egmUN'><center id='egmUN'></center></pre></bdo></b><th id='egmUN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='egmUN'><tfoot id='egmUN'></tfoot><dl id='egmUN'><fieldset id='egmUN'></fieldset></dl></div>

        <legend id='egmUN'><style id='egmUN'><dir id='egmUN'><q id='egmUN'></q></dir></style></legend>
      1. <tfoot id='egmUN'></tfoot>
              <tbody id='egmUN'></tbody>

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

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

                • 本文介紹了將 asyncio 與多處理結(jié)合起來會(huì)出現(xiàn)什么樣的問題(如果有的話)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  當(dāng)他們第一次看到 Python 中的線程時(shí),幾乎每個(gè)人都知道,對(duì)于那些真正想要并行處理的人來說,GIL 讓他們的生活變得悲慘——或者至少給它一個(gè)機(jī)會(huì).

                  As almost everyone is aware when they first look at threading in Python, there is the GIL that makes life miserable for people who actually want to do processing in parallel - or at least give it a chance.

                  我目前正在考慮實(shí)現(xiàn)類似反應(yīng)堆模式的東西.實(shí)際上,我想在一個(gè)類線程上監(jiān)聽傳入的套接字連接,當(dāng)有人嘗試連接時(shí),接受該連接并將其傳遞給另一個(gè)類線程進(jìn)行處理.

                  I am currently looking at implementing something like the Reactor pattern. Effectively I want to listen for incoming socket connections on one thread-like, and when someone tries to connect, accept that connection and pass it along to another thread-like for processing.

                  我(還)不確定我可能面臨什么樣的負(fù)載.我知道目前對(duì)傳入消息設(shè)置了 2MB 的上限.從理論上講,我們每秒可以得到數(shù)千(盡管我不知道實(shí)際上我們是否見過類似的東西).處理消息所花費(fèi)的時(shí)間并不非常重要,但顯然越快越好.

                  I'm not (yet) sure what kind of load I might be facing. I know there is currently setup a 2MB cap on incoming messages. Theoretically we could get thousands per second (though I don't know if practically we've seen anything like that). The amount of time spent processing a message isn't terribly important, though obviously quicker would be better.

                  我正在研究 Reactor 模式,并使用 multiprocessing 庫開發(fā)了一個(gè)小示例,該庫(至少在測試中)似乎工作得很好.但是,現(xiàn)在/很快我們將擁有 asyncio 庫,它將為我處理事件循環(huán).

                  I was looking into the Reactor pattern, and developed a small example using the multiprocessing library that (at least in testing) seems to work just fine. However, now/soon we'll have the asyncio library available, which would handle the event loop for me.

                  asynciomultiprocessing 結(jié)合起來有什么可以咬我的嗎?

                  Is there anything that could bite me by combining asyncio and multiprocessing?

                  推薦答案

                  你應(yīng)該能夠安全地結(jié)合 asynciomultiprocessing 沒有太多麻煩,雖然你不應(yīng)該t 直接使用 multiprocessing.asyncio(以及任何其他基于事件循環(huán)的異步框架)的主要罪過是阻塞事件循環(huán).如果您嘗試直接使用 multiprocessing,則任何時(shí)候您阻塞等待子進(jìn)程,您都會(huì)阻塞事件循環(huán).顯然,這很糟糕.

                  You should be able to safely combine asyncio and multiprocessing without too much trouble, though you shouldn't be using multiprocessing directly. The cardinal sin of asyncio (and any other event-loop based asynchronous framework) is blocking the event loop. If you try to use multiprocessing directly, any time you block to wait for a child process, you're going to block the event loop. Obviously, this is bad.

                  避免這種情況的最簡單方法是使用 BaseEventLoop.run_in_executorconcurrent.futures.ProcessPoolExecutor.ProcessPoolExecutor 是使用 multiprocessing.Process 實(shí)現(xiàn)的進(jìn)程池,但 asyncio 內(nèi)置支持在其中執(zhí)行函數(shù)而不阻塞事件循環(huán).這是一個(gè)簡單的例子:

                  The simplest way to avoid this is to use BaseEventLoop.run_in_executor to execute a function in a concurrent.futures.ProcessPoolExecutor. ProcessPoolExecutor is a process pool implemented using multiprocessing.Process, but asyncio has built-in support for executing a function in it without blocking the event loop. Here's a simple example:

                  import time
                  import asyncio
                  from concurrent.futures import ProcessPoolExecutor
                  
                  def blocking_func(x):
                     time.sleep(x) # Pretend this is expensive calculations
                     return x * 5
                  
                  @asyncio.coroutine
                  def main():
                      #pool = multiprocessing.Pool()
                      #out = pool.apply(blocking_func, args=(10,)) # This blocks the event loop.
                      executor = ProcessPoolExecutor()
                      out = yield from loop.run_in_executor(executor, blocking_func, 10)  # This does not
                      print(out)
                  
                  if __name__ == "__main__":
                      loop = asyncio.get_event_loop()
                      loop.run_until_complete(main())
                  

                  在大多數(shù)情況下,僅此功能就足夠了.如果您發(fā)現(xiàn)自己需要來自 multiprocessing 的其他構(gòu)造,例如 QueueEventManager 等,則有一個(gè)名為 aioprocessing 的第三方庫(完全公開:我寫的),它提供了所有 multiprocessing 數(shù)據(jù)結(jié)構(gòu)的 asyncio 兼容版本.這是一個(gè)演示示例:

                  For the majority of cases, this is function alone is good enough. If you find yourself needing other constructs from multiprocessing, like Queue, Event, Manager, etc., there is a third-party library called aioprocessing (full disclosure: I wrote it), that provides asyncio-compatible versions of all the multiprocessing data structures. Here's an example demoing that:

                  import time
                  import asyncio
                  import aioprocessing
                  import multiprocessing
                  
                  def func(queue, event, lock, items):
                      with lock:
                          event.set()
                          for item in items:
                              time.sleep(3)
                              queue.put(item+5)
                      queue.close()
                  
                  @asyncio.coroutine
                  def example(queue, event, lock):
                      l = [1,2,3,4,5]
                      p = aioprocessing.AioProcess(target=func, args=(queue, event, lock, l)) 
                      p.start()
                      while True:
                          result = yield from queue.coro_get()
                          if result is None:
                              break
                          print("Got result {}".format(result))
                      yield from p.coro_join()
                  
                  @asyncio.coroutine
                  def example2(queue, event, lock):
                      yield from event.coro_wait()
                      with (yield from lock):
                          yield from queue.coro_put(78)
                          yield from queue.coro_put(None) # Shut down the worker
                  
                  if __name__ == "__main__":
                      loop = asyncio.get_event_loop()
                      queue = aioprocessing.AioQueue()
                      lock = aioprocessing.AioLock()
                      event = aioprocessing.AioEvent()
                      tasks = [ 
                          asyncio.async(example(queue, event, lock)),
                          asyncio.async(example2(queue, event, lock)),
                      ]   
                      loop.run_until_complete(asyncio.wait(tasks))
                      loop.close()
                  

                  這篇關(guān)于將 asyncio 與多處理結(jié)合起來會(huì)出現(xià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='oL0HK'><tr id='oL0HK'><dt id='oL0HK'><q id='oL0HK'><span id='oL0HK'><b id='oL0HK'><form id='oL0HK'><ins id='oL0HK'></ins><ul id='oL0HK'></ul><sub id='oL0HK'></sub></form><legend id='oL0HK'></legend><bdo id='oL0HK'><pre id='oL0HK'><center id='oL0HK'></center></pre></bdo></b><th id='oL0HK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oL0HK'><tfoot id='oL0HK'></tfoot><dl id='oL0HK'><fieldset id='oL0HK'></fieldset></dl></div>
                    1. <legend id='oL0HK'><style id='oL0HK'><dir id='oL0HK'><q id='oL0HK'></q></dir></style></legend>

                          <tbody id='oL0HK'></tbody>

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

                        <tfoot id='oL0HK'></tfoot>

                            <bdo id='oL0HK'></bdo><ul id='oL0HK'></ul>
                            主站蜘蛛池模板: 国产有码 | 欧美激情精品久久久久 | 懂色中文一区二区在线播放 | 精品久久久久久久久久久 | 日日操日日舔 | 美女久久 | 国产影音先锋 | 国产精品久久久久久亚洲调教 | 欧美视频福利 | 日韩高清一区 | 婷婷综合五月天 | 亚洲一区免费在线 | 成人美女免费网站视频 | 欧美视频在线播放 | 国产精品欧美一区二区三区 | 粉色午夜视频 | 欧美激情一区 | 国产免费一区二区 | 国产91久久久久蜜臀青青天草二 | av一区在线 | 亚洲一级黄色 | 久久久999国产精品 中文字幕在线精品 | sese视频在线观看 | 97国产精品视频人人做人人爱 | 久久天天综合 | 成人做爰69片免费观看 | 在线观看深夜视频 | 国产成人99久久亚洲综合精品 | 日本a视频 | 国产福利视频 | 在线国产视频观看 | 亚洲精选一区二区 | 精品久久久久久久久久久 | 欧美在线视频二区 | 午夜欧美一区二区三区在线播放 | 男女爱爱福利视频 | 欧美日日 | 一区二区国产精品 | 国产中文在线观看 | av中文字幕在线观看 | 亚洲精品在线视频 |