[Ifeffit] How to use Larch as function server
ASAKURA, Hiroyuki
asakura at moleng.kyoto-u.ac.jp
Wed Mar 13 22:26:28 CDT 2019
Dear Matt,
Thank you for your prompt response.
If I understand correctly, Athena works with Larch by making command strings (Text::Template?) and submitting it to Larch via XML-RPC.
So, it would be the best way, as you suggested.
> server.larch("grp = read_ascii('/path/to/xas/data')")
I understand you don't plan to expose (all of) "low" functions, too.
I intended to use Larch in loose-coupling (without knowledge of a Larch session status) with my app, so I have to go another way.
Thanks again,
Hiroyuki
On 2019/03/03 23:26, Matt Newville wrote:
> Hi Hiroyuki,
>
>
> On Sat, Mar 2, 2019 at 11:40 PM ASAKURA, Hiroyuki <
> asakura at moleng.kyoto-u.ac.jp> wrote:
>
>> Dear all,
>>
>> I would like to use Larch as an external function server.
>> I'm a Python novice, but if I understand correctly, the present server
>> (larch -r) provides access to a Larch process controllable with xmlrpc from
>> outside.
>>
>> However, I would like to do something like below to achieve looser
>> coupling with my future code (maybe not in python).
>> How can I do that?
>> I appreciate any suggestion for my first step to go, though I guess it is
>> a bit far from the Larch way.
>>
>
> Running Larch in "server mode" is definitely possible but also sort of
> advanced programming. I should clarify something: you should start a
> server with the `larch_server start`, not `larch -r`. This should be
> removed from the `larch` command and fixed in the docs.
>
> Once the server process is running, client processes can send commands to
> run and receive data from the larch session running in the server process.
> The server process can be on a different machine, but I should admit that
> I've only done this in tests. The functions available to the client are
> pretty limited (definitely not all larch commands) and meant to be "high
> level". They include:
>
> larch send larch commands as strings to the server
> get_data get data encoded in json
> get_rawdata get data with json encoding
> get_messages, len_messages get messages printed by the server
> ls, chdir, cd, cwd setting the working directory for the server
> shutdown, set_keepalive_time shutdown server, delay shutdown due to no activity
> set_client_info, get_client_info set/get information about the client using this server
>
> There isn't anything as specific as "read_ascii()" function. Instead, you
> would do
>
> from xmlrpc.client import ServerProxy
> server = ServerProxy("http://127.0.0.1:4966")
>
> # send a string to run as a larch command
> server.larch("grp = read_ascii('/path/to/xas/data')")
>
> We could consider adding more exposed functions, but the server has to
> register each exposed function (see
> https://github.com/xraypy/xraylarch/blob/master/larch/xmlrpc_server.py#L121
> ), so I would not want to try to expose every function in the Larch API.
>
> The client application can be in any language that supports XML-RPC
> communication. Many languages do have an XML-RPC library, though they
> might differ in some features like how to unpack data into native
> datatypes. For example, a Perl implementation so that Demeter can use a
> larch server as its backend is at
> https://github.com/bruceravel/demeter/blob/master/lib/Larch.pm
>
> If you are interested in doing that for another language let me know if I
> can be of any help.
>
> Hope that helps, but if I missed the some part of your question, please let
> me know....
>
> --Matt
>
>
> _______________________________________________
> Ifeffit mailing list
> Ifeffit at millenia.cars.aps.anl.gov
> http://millenia.cars.aps.anl.gov/mailman/listinfo/ifeffit
> Unsubscribe: http://millenia.cars.aps.anl.gov/mailman/options/ifeffit
>
--
ASAKURA, Hiroyuki (Ph.D)
Program-Specific Senior Lecturer (ESICB)
T. Tanaka Lab., ESICB, Kyoto University, Japan
asakura at moleng.kyoto-u.ac.jp
http://www.moleng.kyoto-u.ac.jp/~moleng_04/asakura/
More information about the Ifeffit
mailing list