可能的内存泄露导致程序退出时直接删除内存共享块:
resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked shared_memory objects to clean up at shutdown warnings.warn('resource_tracker: There appear to be %d ')
解决办法,不能直接使用close()函数,正确退出方法:
from multiprocessing import resource_tracker
if shm_a is not None:
shm_a.close()
resource_tracker.unregister(shm_a._name, "shared_memory")
手动关闭或者异常退出时上述问题依然存在,通过检测退出信号可以解决:
def handler(signal, frame):
if shm_a is not None:
shm_a.close()
resource_tracker.unregister(shm_a._name, "shared_memory")
# 注册信号处理事件
signal.signal(signal.SIGINT, handler)