Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asynchronous calls #45

Closed
farshidtz opened this issue Dec 25, 2016 · 3 comments
Closed

Asynchronous calls #45

farshidtz opened this issue Dec 25, 2016 · 3 comments

Comments

@farshidtz
Copy link

Hello there,

I'm getting PyroException("result msg out of sync") when calling normal method asynchronously from Java. Is there any way to bypass the sequenceNr checking or is this required for mapping each "result msg" to the callee?

Thanks for the great work! :)

@irmen
Copy link
Owner

irmen commented Dec 26, 2016

Please show some code that explains how you "call normal method asynchronously".
But yeah the exception is thrown when a Pyro(lite) proxy object somehow gets a reply from the server that didn't belong the the request that was sent in that particular thread. You should not use a single Pyro proxy in multiple different threads.

@farshidtz
Copy link
Author

I'm calling pyro methods from handlers of an API. In the example below predict can be called multiple times asynchronously. I can use a mutex or synchronized method to force sequential calls but that would cause long queues.

public class ExternPythonPyro {
    PyroProxy pyro;

    public ExternPythonPyro() throws Exception {
        NameServerProxy ns = NameServerProxy.locateNS(null);
        pyro = new PyroProxy(ns.lookup("python-learning-agent"));
        ns.close();
    }

    public void learn(Object input) throws Exception {
        pyro.call_oneway("learn", input);
    }

    public Integer predict(Object input) throws Exception {
        return (Integer) pyro.call("predict", input);
    }

    public void destroy() throws Exception {
        pyro.close();
    }

}

You should not use a single Pyro proxy in multiple different threads.

Is this the case only for Pyrolite or it's a limitation of Pyro in general?

Thanks a lot

@irmen
Copy link
Owner

irmen commented Dec 26, 2016

It's just the way the underlying socket connections work: they're fully synchronous (blocking) request/replies. The thread using a socket to do a request sits waiting for the response to come back over the same socket. Other threads interfering with the same socket will destroy the integrity of the communication (hence the sequence number check).

Pyro (the python library) does internal locking in its proxies for you. Pyrolite doesn't so you should lock yourself. Or make a pool of proxies where you allocate one per thread.

@irmen irmen closed this as completed Dec 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants