Hi!
I’m using: SWI-Prolog version 8.2.4 on Windows.
Consider this use case: I am running a program which connects to a database and performs some calculations. When I run it from my home, it’s much slower than running from a company server because it goes through the VPN. Therefore, I want to run it remotely. I tried to use pengine_rpc
for this. I created a pengine server which does nothing but run a program with create_process
and write back the output. I would like to connect to this server from another machine (my laptop), but so far, I have only tested it locally.
On Linux, this works as expected. On Windows 10, the rpc call gets stuck until I query the same predicate on the server prolog instance.
To clarify:
Linux:
swipl instance 1:
- start http_server with pengines.
- query pengine_rpc(localhost… run…) → works immediately.
swipl instance 2: - query pengine_rpc(localhost… run…) → works immediately.
Windows
swipl instance 1:
- start http_server with pengines.
- query
pengine_rpc(localhost... run...)
→ works immediately.
swipl instance 2: - query
pengine_rpc(localhost... run...)
→ is stuck.
Back to instance 1: - query
run(...)
→ works immediately and also the query in instance 2 finishes.pengines_rpc(..., member(X,[1,2]))
or similar on the server also works for this purpose, but queries that are neither process- nor pengines-related don’t.
My code looks like this:
server.pl:
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- http_server(http_dispatch, [port(4343)]).
:- use_module(library(pengines)).
:- use_module(pengine_sandbox:abr).
:- use_module(library(sandbox)).
:- multifile sandbox:safe_primitive/1.
sandbox:safe_primitive(abr:run(_,_,_)).
abr.pl:
:- module(abr, [run/3]).
run(Cmd, ArgStr, Output) :-
split_string(ArgStr, " ", "", Args),
process_create(path(Cmd), Args, [stdout(pipe(OutStr)), stderr(pipe(OutStr))]),
read_string(OutStr, _, Output),
close(OutStr).
Query:
?- pengine_rpc('http://localhost:4343', run(ls, "..", O)).
Is there a known limitation or something I can do to work around this? Anything needs to be closed explicitly?
Thanks a lot!
Mike