Python Forum
Sharing objects in multiple processes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sharing objects in multiple processes
#1
Here's a python package I made for sharing complex objects between processes.

git: https://github.com/dRoje/pipe-proxy

The idea is you create a proxy for your object and pass it to a process. Then you use the proxy like you have a reference to the original object. Although you can only use method calls, so accessing object variables is done threw setters and getters.

Say we have an object called ‘example’, creating proxy and proxy listener is easy:

from pipeproxy import proxy 
example = Example() 
exampleProxy, exampleProxyListener = proxy.createProxy(example)
Now you send the proxy to another process.

p = Process(target=someMethod, args=(exampleProxy,)) p.start()
Use it in the other process as you would use the original object (example):

def someMethod(exampleProxy):
    ...
    exampleProxy.originalExampleMethod()
    ...
But you do have to listen to it in the main process:
exampleProxyListener.listen()
Read more and find examples here:

http://matkodjipalo.com/index.php/2017/1...rocessing/
Reply


Messages In This Thread
Sharing objects in multiple processes - by duje - Nov-13-2017, 04:41 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020