Initial work on using multiprocessing SharedMemory feature#19
Initial work on using multiprocessing SharedMemory feature#19ymd-h merged 4 commits intoymd-h:masterfrom
Conversation
It is working well, tested on Ray, Linux.
|
@jamartinh Can you make a fallback for Python 3.7? I think It seems that Also I've set up unit test GitHub Actions for PR. From the next update, maybe it will run, too. |
|
Additional comments;
|
|
Hi @ymd-h I will check all this details ! This is a preliminary version to show you how it is going. |
|
@jamartinh I also would like to discuss another point; Modifying import base64
import ctypes
import multiprocessing as mp
from multiprocessing.managers import SyncManager
import time
import ray
def run():
ray.init()
m = SyncManager()
m.start()
v = m.Value(ctypes.c_int, 0)
lock = m.Lock()
authkey = mp.current_process().authkey
# Encode base64 to avoid following error:
# TypeError: Pickling an AuthenticationString object is disallowed for security reasons
encoded = base64.b64encode(authkey)
def auth_fn(*args):
mp.current_process().authkey = base64.b64decode(encoded)
ray.worker.global_worker.run_function_on_all_workers(auth_fn)
@ray.remote
def remote_lock(v, L):
with L:
v.value += 1
try:
print(v.value) # -> 0
ray.get([remote_lock.remote(v, lock),
remote_lock.remote(v, lock)])
print(v.value) # -> 2
finally:
m.shutdown()
if __name__ == "__main__":
run()PS1: I was wrong. PS2: If you feel our request is too much, please let us know. We can take over at any time. |
|
@ymd-h thanks ! |
+ fix to don't change authkey + clean source code + clean pickling functions set/get state
|
@ymd-h thanks, Now it is just: authkey = mp.current_process().authkey
encoded = base64.b64encode(authkey)
def auth_fn(*args):
mp.current_process().authkey = base64.b64decode(encoded)
print("multiprocessing authkey set")
ray.worker.global_worker.run_function_on_all_workers(auth_fn)And no more issues with authkey inside nor dangerous side effects on a node by changing the authkey Thanks for the tips! |
|
it rest the fallback for python<3.8 |
|
@jamartinh
I think constructor option is enough unless there are non-negligible overhead at Unfortunately, it seems that it doesn't work on Windows and macOS. |
…Windows is that Windows only accepts spawn (not fork) so classes have to support explicitly pickling and unpickling all the objects, especially the synchronized and shared memory ones. I have run the test locally on a Windows 2016 server python3.9 and mp.py tests succeeded.
|
@jamartinh If you have any ideas for import section, please open a new discussion thread. Especially, removing |
|
@ymd-h It seems my fingers automatically pressed the code formatter because I use it all time, yes it is dangerous since it optimizes imports and do many other things. |
|
Well, after all, I think I can't be dedicating more time to this. |
|
@jamartinh I'm sorry if was being impolite or too straightforward in our discussion. I hope for your success. Best wishes. |
It is working well, tested on Ray, Linux.