Adding concurrency and Functor conveniences #110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goals
Pyro5 is a great library to accelerate development for python IPC projects. However, it lacks two things that are necessary for our use cases.
Firstly, it doesn't have convenient concurrent communication support. Only 1 thread on the client can use a Proxy at once. The stated workaround for this is to pass around the URI instead of the proxy, but this has 2 drawbacks:
Secondly, it is inconvenient to not be able to auto-proxy methods with un-exposed classes. The two biggest occurrences of this are: giving callbacks to the server that are regular functions or lambdas (base class e.g.:
builtins.function) or using a method of a normal object as a callback (i.e. my_queue.put).Implementation
Concurrency
There are some challenges to implementing socket-level concurrency in Pyro. The protocol expects messages to come in the right order, so un-collating a concurrent message stream would be a bit annoying. So with the stated goals in mind, I decided to create a new class,
ConcurrentProxythat will perform the intended workflow, but automatically.If you are not careful with this, it is possible to cause significant memory growth that is unnecessary as well as unnecessary chatter.
Function Calling
I created a new class,
Functorthat can be used to wrap and expose methods that otherwise aren't exposed by their original owning class. To make this work more conveniently, I also removed__call__from the dunder method private list.Now you can wrap functions or lambdas with
Pyro5.api.Functorand call them like functions on the server side.Feedback Request
I am sure there is a better way to correctly manage concurrent proxies. So I am interested in feedback there.
Also, I am not totally sure why
__call__was on the private list to begin with. If there is some reason I am missing, I would be interested to know.