<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 01/28/2015 07:19 PM, Matthieu Tourne
wrote:<br>
</div>
<blockquote
cite="mid:CAAGYmFfFNMyvhysj=OFnPtqXLouWhT=6D465YePDZ4wJkRtp5g@mail.gmail.com"
type="cite">
<div dir="ltr">Hi,
<div><br>
</div>
<div>I started using py_interface as a layer to do rpc into an
Erlang system, receive and send message, and eventually
provide functionality to the that Erlang system.</div>
<div><br>
</div>
<div>One of the functions on the Erlang side would be :</div>
<div><br>
</div>
<div>handle_call({subscribe, Channel}, From, State) -></div>
<div> %% Saves From as a subscriber of this channel into the
State</div>
<div> %% When something will arrive on the Channel From will
get a message.</div>
<div><br>
</div>
<div>The problem is when I'm sending an rpc:call via
py_interface (a call message on the rex mailbox essentially).
It seems that the pid associated to that rpc essentially
disappears right when the rpc is completed.</div>
<div><br>
</div>
<div>As I gathered from this example [1], an alternative way to
do this would be to rewrite my handle_call this way : </div>
<div><br>
</div>
<div>handle_call({subscribe, Channel, SubscribingPid}, _From,
State) -><br>
</div>
<div> %% Saves SubscribingPid instead of From.</div>
<div><br>
</div>
<div>And I would pass in the Pid of an active mailbox from my
py_interface hidden node.</div>
<div><br>
</div>
<div>My question is two fold, would there be a way to keep a
live Pid in the system (maybe [2] answers this problem as a
byproduct), for longer than getting a result to that rpc call.</div>
<div>Or would a proper way to do this be to have a proxy process
to make the link between rpc's and a live mailbox in my hidden
node.</div>
<div>Also, is a hidden node the best way of achieving all of
this ?</div>
</div>
</blockquote>
py_interface makes the running Python interpreter into a hidden
node, similar to a cnode
(<a class="moz-txt-link-freetext" href="http://www.erlang.org/doc/tutorial/cnode.html">http://www.erlang.org/doc/tutorial/cnode.html</a>), just using Python
source code (like jinterface does with Java source code). You could
probably modify the py_interface source code to run as an Erlang
port (<a class="moz-txt-link-freetext" href="http://www.erlang.org/doc/tutorial/c_port.html">http://www.erlang.org/doc/tutorial/c_port.html</a>). In both
cases, all Python usage will have a single connection bottleneck (a
single socket for a cnode and a single pair of pipes for a port).
Depending on the Python source code, you could argue that it will
never matter due to the global interpreter lock.<br>
<br>
However, if you do care about Python latency, it is more efficient
to use the Python CloudI API. To do RPC you would send a service
request to another CloudI service (based on your example, an Erlang
CloudI service). An example of a Python service is at
<a class="moz-txt-link-freetext" href="http://cloudi.org/#Python">http://cloudi.org/#Python</a> to show how a service request can be
handled in Python (adding a send_sync CloudI API function call
(<a class="moz-txt-link-freetext" href="http://cloudi.org/api.html#1_send_sync">http://cloudi.org/api.html#1_send_sync</a>) would be the same as doing
RPC). The Python CloudI API is implemented only in Python in the
cloudi module and with Python/C integration in the cloudi_c module
(the quickest Python integration).<br>
<br>
<blockquote
cite="mid:CAAGYmFfFNMyvhysj=OFnPtqXLouWhT=6D465YePDZ4wJkRtp5g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Any working example of what I'm trying to achieve would be
greatly appreciated,</div>
</div>
</blockquote>
I don't use py_interface, but the example you are probably looking
for is
<a class="moz-txt-link-freetext" href="https://github.com/tomas-abrahamsson/py_interface/blob/master/examples/test_remote_exec.py">https://github.com/tomas-abrahamsson/py_interface/blob/master/examples/test_remote_exec.py</a>
. You specify the remote node, module name, and function name on
the command line of the script and it performs the RPC call for you,
converting types in the process.<br>
<br>
<blockquote
cite="mid:CAAGYmFfFNMyvhysj=OFnPtqXLouWhT=6D465YePDZ4wJkRtp5g@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><br>
</div>
<div>Thank you!</div>
<div>Matthieu</div>
<div><br>
</div>
<div>[1] <a moz-do-not-send="true"
href="https://github.com/adamtornhill/tinch_pp/blob/master/test/chat_server.erl">https://github.com/adamtornhill/tinch_pp/blob/master/test/chat_server.erl</a><br>
</div>
<div>[2] <a moz-do-not-send="true"
href="https://github.com/cloudant/rexi">https://github.com/cloudant/rexi</a><br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
</blockquote>
<br>
</body>
</html>