Hello,
let say I have some actors running on my system (ray2.0.0.dev, python 3.8.5, Mint 19.3). Actors operate on a shared memory chunk. When they receive a dict of named shared memories, they use it like this:
from multiprocessing import shared_memory
def refresh_main_arrays (self, main_arrays):
if main_arrays is None:
return
else:
self.main_arrays = main_arrays
for var in main_arrays.keys ():
shp, dty = main_arrays[var]
shm_tmp = shared_memory.SharedMemory(name=var)
arr_tmp = np.ndarray(shape=shp, dtype = dty, \
buffer = shm_tmp.buf)
try:
setattr(self,var+'_shm', shm_tmp)
setattr(self,var, arr_tmp)
except:
print ("acquisition of array memory failed")
This runs without error for a proper dict main_arrays . Before I terminate actors, I try to release shared memory resources:
def close_main_arrays (self):
if self.main_arrays is None:
return
for var in self.main_arrays.keys ():
shm_tmp = self.__getattribute__(var+"_shm")
try:
shm_tmp.close ()
except:
print ("failure during unlinking and closure of memory handle " + var + "_shm")
which also runs without error. But when I terminate an actor:
ray.get ([H.close_main_arrays.remote () for H in Hs])
ray.get (mnp.close_and_unlock_main_arrays.remote ())
ray.kill (mnp)
for each in Hs:
ray.kill (each)
It is followed with an immediate flush of warnings:
(pid=8316) /home/coded/anaconda3/envs/ray2py38/lib/python3.8/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 5 leaked shared_memory objects to clean up at shutdown
(pid=8316) warnings.warn('resource_tracker: There appear to be %d '
(pid=8316) /home/coded/anaconda3/envs/ray2py38/lib/python3.8/multiprocessing/resource_tracker.py:229: UserWarning: resource_tracker: '/mnp_yx_size': [Errno 2] No such file or directory: '/mnp_yx_size'
(pid=8316) warnings.warn('resource_tracker: %r: %s' % (name, e))
(pid=8316) /home/coded/anaconda3/envs/ray2py38/lib/python3.8/multiprocessing/resource_tracker.py:229: UserWarning: resource_tracker: '/mnp_size': [Errno 2] No such file or directory: '/mnp_size'
(pid=8316) warnings.warn('resource_tracker: %r: %s' % (name, e))
(pid=8316) /home/coded/anaconda3/envs/ray2py38/lib/python3.8/multiprocessing/resource_tracker.py:229: UserWarning: resource_tracker: '/mnp': [Errno 2] No such file or directory: '/mnp'
(pid=8316) warnings.warn('resource_tracker: %r: %s' % (name, e))
(pid=8316) /home/coded/anaconda3/envs/ray2py38/lib/python3.8/multiprocessing/resource_tracker.py:229: UserWarning: resource_tracker: '/mnp_yz_dist': [Errno 2] No such file or directory: '/mnp_yz_dist'
(pid=8316) warnings.warn('resource_tracker: %r: %s' % (name, e))
(pid=8316) /home/coded/anaconda3/envs/ray2py38/lib/python3.8/multiprocessing/resource_tracker.py:229: UserWarning: resource_tracker: '/mnp_state': [Errno 2] No such file or directory: '/mnp_state'
(pid=8316) warnings.warn('resource_tracker: %r: %s' % (name, e))
Output from spyder call 'get_cwd':
And this repeats for every PID. It seems to me that resource_tracker fails to notice that I’ve released the resources and try to do it again just to fail. Also, if I try to access shared memory after close_and_unlink_main_arrays (), actor dies with:
RayActorError: The actor died unexpectedly before finishing this task. Check python-core-worker-*.log files for more information.
So, it seems that close_main_arrays does its job. What confuses me is that the IDENTICAL warnings are raised even if I DON’T call close_main_arrays before killing actors and I cannot tell if this is ray or multiprocessing issue. Is this the right place to discuss this and is there a guidance how can I make ray and multiprocessing play nice with each other?