Hi Hiroyuki, On Sat, Mar 2, 2019 at 11:40 PM ASAKURA, Hiroyuki < asakura@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