How to make sure child process finishes copying data into shared memory before join() is called?

↘锁芯ラ 提交于 2019-12-11 16:11:48

问题


I am using multiprocessing.Process to load some images and store them in a shared memory as explained here. The problem is, sometimes my code crashes due to a huge memory spike at completely random times. I just had an idea of what might be causing this: the process does not have had enough time to copy the contents of the image into the shared memory in RAM by the time join(). To test my hypothesis I added time.sleep(0.015) after doing join() on each of my processes and this has already reduced the number of memory spikes by about 90% or more. However, I'm still not 100% certain whether not getting memory spikes as often is because that little amount of time could help the data to get fully transferred to the shared memory or not.

So I wonder, is there a way to make sure a child process has finished copying data to memory before .join() is called? I do not want to use a fixed number when calling time.sleep(). It would be great to to know when the data has been fully transferred to the shared memory and then do join().

来源:https://stackoverflow.com/questions/56812806/how-to-make-sure-child-process-finishes-copying-data-into-shared-memory-before-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!