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

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

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

      <tfoot id='LOWuz'></tfoot>

        <bdo id='LOWuz'></bdo><ul id='LOWuz'></ul>
      <legend id='LOWuz'><style id='LOWuz'><dir id='LOWuz'><q id='LOWuz'></q></dir></style></legend>

        在子進(jìn)程已經(jīng)啟動后授予對共享內(nèi)存的訪問權(quán)限

        Giving access to shared memory after child processes have already started(在子進(jìn)程已經(jīng)啟動后授予對共享內(nèi)存的訪問權(quán)限)

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

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

                • <tfoot id='djNGL'></tfoot><legend id='djNGL'><style id='djNGL'><dir id='djNGL'><q id='djNGL'></q></dir></style></legend>
                  本文介紹了在子進(jìn)程已經(jīng)啟動后授予對共享內(nèi)存的訪問權(quán)限的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  如果數(shù)據(jù)僅在子進(jìn)程生成后可用(使用 multiprocessing.Process)?

                  How do I give child processes access to data in shared memory if the data is only available after the child processes have been spawned (using multiprocessing.Process)?

                  我知道 multiprocessing.sharedctypes.RawArray,但我不知道如何讓我的子進(jìn)程訪問在進(jìn)程已經(jīng)啟動后創(chuàng)建的 RawArray .

                  I am aware of multiprocessing.sharedctypes.RawArray, but I can't figure out how to give my child processes access to a RawArray that is created after the processes have already started.

                  數(shù)據(jù)由父進(jìn)程生成,數(shù)據(jù)量事先不知道.

                  The data is generated by the parent process, and the amount of data is not known in advance.

                  如果不是 GIL 我會使用線程來代替這將完成這項任務(wù)簡單一點.使用非 CPython 實現(xiàn)不是一種選擇.

                  If not for the GIL I'd be using threading instead which will make this task a little simpler. Using a non-CPython implementation is not an option.

                  查看 muliprocessing.sharedctypes,看起來共享 ctype 對象被分配了 使用 mmaped 內(nèi)存.

                  Looking under the hood of muliprocessing.sharedctypes, it looks like shared ctype objects are allocated using mmaped memory.

                  所以這個問題真的可以歸結(jié)為:如果 mmap() 在子進(jìn)程生成后被父進(jìn)程調(diào)用,子進(jìn)程能否訪問匿名映射的內(nèi)存?

                  So this question really boils down to: Can a child process access an anonymously mapped memory if mmap() was called by the parent after the child process was spawned?

                  這有點像 this問題,除了在我的例子中 mmap() 的調(diào)用者是父進(jìn)程而不是子進(jìn)程.

                  That's somewhat in the vein of what's being asked in this question, except that in my case the caller of mmap() is the parent process and not the child process.

                  我創(chuàng)建了自己的 RawArray 版本,它在底層使用了 shm_open().只要標(biāo)識符(tag)匹配,生成的共享 ctypes 數(shù)組就可以與任何進(jìn)程共享.

                  I created my own version of RawArray that uses shm_open() under the hood. The resulting shared ctypes array can be shared with any process as long as the identifier (tag) matches.

                  請參閱此答案 了解詳細(xì)信息和示例.

                  See this answer for details and an example.

                  推薦答案

                  您的問題聽起來非常適合 posix_ipcsysv_ipc 模塊,它們公開用于共享內(nèi)存、信號量和消息隊列的 POSIX 或 SysV API.那里的特征矩陣包括在他提供的模塊中挑選的極好的建議.

                  Your problem sounds like a perfect fit for the posix_ipc or sysv_ipc modules, which expose either the POSIX or SysV APIs for shared memory, semaphores, and message queues. The feature matrix there includes excellent advice for picking amongst the modules he provides.

                  匿名 mmap(2) 區(qū)域的問題在于,您無法輕松地與其他進(jìn)程共享它們——如果它們是文件支持的,這很容易,但如果您不這樣做實際上需要文件來做其他事情,感覺很傻.您可以clone(2) 系統(tǒng)調(diào)用中使用 CLONE_VM 標(biāo)志,如果這是在 C 中,但我不想嘗試使用它帶有一個可能對內(nèi)存安全做出假設(shè)的語言解釋器.(即使在 C 語言中也會有點危險,因為五年后的維護程序員可能CLONE_VM 行為感到震驚.)

                  The problem with anonymous mmap(2) areas is that you cannot easily share them with other processes -- if they were file-backed, it'd be easy, but if you don't actually need the file for anything else, it feels silly. You could use the CLONE_VM flag to the clone(2) system call if this were in C, but I wouldn't want to try using it with a language interpreter that probably makes assumptions about memory safety. (It'd be a little dangerous even in C, as maintenance programmers five years from now might also be shocked by the CLONE_VM behavior.)

                  但是 SysV 和更新的 POSIX 共享內(nèi)存映射甚至允許不相關(guān)的進(jìn)程通過標(biāo)識符附加和分離共享內(nèi)存,因此您需要做的就是與使用映射的進(jìn)程共享創(chuàng)建映射的進(jìn)程的標(biāo)識符,然后當(dāng)您在映射中操作數(shù)據(jù)時,它們可同時供所有進(jìn)程使用,而無需任何額外的解析開銷.shm_open(3) 函數(shù)返回一個 int,在以后調(diào)用 ftruncate(2) 時用作文件描述符mmap(2),因此其他進(jìn)程可以使用共享內(nèi)存段,而無需在文件系統(tǒng)中創(chuàng)建文件——即使使用它的所有進(jìn)程都已退出,該內(nèi)存仍將持續(xù)存在.(對于 Unix 來說可能有點奇怪,但它很靈活.)

                  But the SysV and newer POSIX shared memory mappings allow even unrelated processes to attach and detach from shared memory by identifier, so all you need to do is share the identifier from the processes that create the mappings with the processes that consume the mappings, and then when you manipulate data within the mappings, they are available to all processes simultaneously without any additional parsing overhead. The shm_open(3) function returns an int that is used as a file descriptor in later calls to ftruncate(2) and then mmap(2), so other processes can use the shared memory segment without a file being created in the filesystem -- and this memory will persist even if all processes using it have exited. (A little strange for Unix, perhaps, but it is flexible.)

                  這篇關(guān)于在子進(jìn)程已經(jīng)啟動后授予對共享內(nèi)存的訪問權(quán)限的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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 中將多個參數(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)其中一個工作進(jìn)程確定不再需要完成工作時,如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯誤的另一個混淆,“模塊對象沒有屬性“f)
                      <bdo id='L0196'></bdo><ul id='L0196'></ul>
                    • <legend id='L0196'><style id='L0196'><dir id='L0196'><q id='L0196'></q></dir></style></legend>

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

                        <tbody id='L0196'></tbody>

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

                          • <tfoot id='L0196'></tfoot>
                          • 主站蜘蛛池模板: 一区视频在线播放 | 99伊人网| 欧美久久久久久 | av在线二区 | 狠狠操狠狠干 | 免费美女网站 | 日韩成人 | 国产色片| 福利视频网站 | 综合五月婷 | 成人在线观看免费视频 | 插插插干干干 | 欧美一区二区三区视频在线播放 | 亚洲一区二区三区四区视频 | 国产成人免费一区二区60岁 | 99精品欧美一区二区蜜桃免费 | 九九视频网 | 亚洲精品视频在线播放 | 日韩中文字幕在线视频 | 国产精品18久久久 | 成人综合一区二区 | 美女一级a毛片免费观看97 | 欧美成人激情视频 | 久久精品女人天堂av | 国产一区二区精品在线观看 | 一区二区三区四区av | 剑来高清在线观看 | 欧美黄色网络 | 黄色免费看 | 中文字幕在线中文 | 久草电影网 | 久久久久久国产免费视网址 | 成人污污视频 | 亚洲精品一区中文字幕乱码 | 欧美久久久网站 | 黄篇网址 | 精品视频一区在线 | 欧美 日韩精品 | 久久1区 | 亚洲天堂av一区 | h在线播放|