Merge pull request #3310 from Skgland/process_wait-release
add `release(Bool)` option to `process_wait/3`
This commit is contained in:
@@ -95,10 +95,12 @@ process_wait(Process, Status) :- call_with_error_context(process_wait(Process, S
|
|||||||
% `Options` is a a list of the following options
|
% `Options` is a a list of the following options
|
||||||
%
|
%
|
||||||
% * timeout(Timeout) supported values for `Timeout` are 0 or `infinite`
|
% * timeout(Timeout) supported values for `Timeout` are 0 or `infinite`
|
||||||
|
% * release(Bool) supported values for `Bool` are `true` or `false`
|
||||||
%
|
%
|
||||||
% Each options may be specified at most once, when an option is not specified the following defaults apply:
|
% Each options may be specified at most once, when an option is not specified the following defaults apply:
|
||||||
%
|
%
|
||||||
% - timeout(infinite)
|
% - timeout(infinite)
|
||||||
|
% - release(true)
|
||||||
%
|
%
|
||||||
process_wait(Process, Status, Options) :- call_with_error_context(process_wait_(Process, Status, Options), predicate-process_wait/3).
|
process_wait(Process, Status, Options) :- call_with_error_context(process_wait_(Process, Status, Options), predicate-process_wait/3).
|
||||||
|
|
||||||
@@ -106,17 +108,29 @@ process_wait_(Process, Status, Options) :-
|
|||||||
valid_process(Process),
|
valid_process(Process),
|
||||||
check_options(
|
check_options(
|
||||||
[
|
[
|
||||||
option([timeout], valid_timeout, timeout(infinite), timeout(Timeout))
|
option([timeout], valid_timeout, timeout(infinite), timeout(Timeout)),
|
||||||
|
option([release], valid_release, release(true), release(Release))
|
||||||
],
|
],
|
||||||
Options,
|
Options,
|
||||||
process_wait_option
|
process_wait_option
|
||||||
),
|
),
|
||||||
'$process_wait'(Process, Exit, Timeout),
|
'$process_wait'(Process, Exit, Timeout),
|
||||||
|
((true = Release) -> '$process_release'(Process) ; true),
|
||||||
Exit = Status.
|
Exit = Status.
|
||||||
|
|
||||||
valid_timeout(timeout(infinite)).
|
valid_timeout(timeout(infinite)).
|
||||||
valid_timeout(timeout(0)).
|
valid_timeout(timeout(0)).
|
||||||
|
|
||||||
|
valid_release(release(Arg)) :-
|
||||||
|
( var(Arg) -> instantiation_error([])
|
||||||
|
; valid_bool(Arg) -> true
|
||||||
|
; domain_error(boolean, Arg, [])
|
||||||
|
).
|
||||||
|
|
||||||
|
|
||||||
|
valid_bool(true).
|
||||||
|
valid_bool(false).
|
||||||
|
|
||||||
|
|
||||||
%% process_kill(+Process).
|
%% process_kill(+Process).
|
||||||
%
|
%
|
||||||
@@ -141,8 +155,7 @@ process_release(Process) :- call_with_error_context(process_release_(Process), p
|
|||||||
|
|
||||||
process_release_(Process) :-
|
process_release_(Process) :-
|
||||||
valid_process(Process),
|
valid_process(Process),
|
||||||
process_wait(Process, _),
|
process_wait(Process, _).
|
||||||
'$process_release'(Process).
|
|
||||||
|
|
||||||
|
|
||||||
must_be_known_options(Valid, Options, Domain) :- call_with_error_context(must_be_known_options_(Valid, [], Options, Domain),predicate-must_be_known_options/3).
|
must_be_known_options(Valid, Options, Domain) :- call_with_error_context(must_be_known_options_(Valid, [], Options, Domain),predicate-must_be_known_options/3).
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
```trycmd
|
```trycmd
|
||||||
$ scryer-prolog -f --no-add-history -g 'use_module(library(process)), process_create("false", [], [process(P)]), process_wait(P, exit(1)), halt'
|
$ scryer-prolog -f --no-add-history -g 'use_module(library(process)), process_create("false", [], [process(P)]), process_id(P, Pid), write(pid=Pid), nl, process_wait(P, exit(1)), halt'
|
||||||
|
pid=[..]
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -12,3 +13,32 @@ $ scryer-prolog -f --no-add-history -g 'use_module(library(process)), use_modul
|
|||||||
$ scryer-prolog -f --no-add-history -g 'use_module(library(process)), process_create("sh", ["-c", "sleep 5"], [process(P), stdout(null)]), process_kill(P), process_wait(P, killed(9)), halt'
|
$ scryer-prolog -f --no-add-history -g 'use_module(library(process)), process_create("sh", ["-c", "sleep 5"], [process(P), stdout(null)]), process_kill(P), process_wait(P, killed(9)), halt'
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
existence error is expected as the process was released, but the program shouldn't panic, see [issue 3300](https://github.com/mthom/scryer-prolog/issues/3300)
|
||||||
|
```trycmd
|
||||||
|
$ scryer-prolog -f --no-add-history -t halt -g 'use_module(library(process)), process_create("false", [], [process(P)]), process_id(P, Pid), write(pid=Pid), nl, process_wait(P, exit(1)), process_id(P, Pid2), write(pid=Pid2), nl'
|
||||||
|
? failed
|
||||||
|
pid=[..]
|
||||||
|
use_module(library(process)),process_create("false",[],[process(P)]),process_id(P,Pid),write(pid=Pid),nl,process_wait(P,exit(1)),process_id(P,Pid2),write(pid=Pid2),nl causes: error(existence_error(process,$dropped_value),[predicate-process_id/2|process_id/2])
|
||||||
|
|
||||||
|
thread 'main'[..] panicked at src/machine/loader.rs:[..]:[..]:
|
||||||
|
called `Result::unwrap()` on an `Err` value: ()
|
||||||
|
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
existence error is expected as the process was released, but the program shouldn't panic, see [issue 3300](https://github.com/mthom/scryer-prolog/issues/3300)
|
||||||
|
```trycmd
|
||||||
|
$ scryer-prolog -f --no-add-history -t halt -g 'use_module(library(process)), process_create("false", [], [process(P)]), process_id(P, Pid), write(pid=Pid), nl, process_wait(P, exit(1), [release(false)]), process_id(P, Pid2), write(pid=Pid2), nl, process_release(P), process_id(P, Pid3), write(pid=Pid3), nl'
|
||||||
|
? failed
|
||||||
|
pid=[..]
|
||||||
|
pid=[..]
|
||||||
|
use_module(library(process)),process_create("false",[],[process(P)]),process_id(P,Pid),write(pid=Pid),nl,process_wait(P,exit(1),[release(false)]),process_id(P,Pid2),write(pid=Pid2),nl,process_release(P),process_id(P,Pid3),write(pid=Pid3),nl causes: error(existence_error(process,$dropped_value),[predicate-process_id/2|process_id/2])
|
||||||
|
|
||||||
|
thread 'main'[..] panicked at src/machine/loader.rs:[..]:[..]:
|
||||||
|
called `Result::unwrap()` on an `Err` value: ()
|
||||||
|
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||||
|
|
||||||
|
```
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
```trycmd
|
```trycmd
|
||||||
$ scryer-prolog -f --no-add-history -g 'use_module(library(process)), process_create("cmd", ["/C", "exit", "1"], [process(P)]), process_wait(P, exit(1)), halt'
|
$ scryer-prolog -f --no-add-history -g 'use_module(library(process)), process_create("cmd", ["/C", "exit", "1"], [process(P)]), process_id(P, Pid), write(pid=Pid), nl, process_wait(P, exit(1)), halt'
|
||||||
|
pid=[..]
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -7,3 +8,30 @@ $ scryer-prolog -f --no-add-history -g 'use_module(library(process)), process_cr
|
|||||||
$ scryer-prolog -f --no-add-history -g 'use_module(library(process)), use_module(library(format)), process_create("cmd", [], [process(P), stdout(null), stdin(pipe(S))]), format(S, "exit 1~n", []), process_wait(P, exit(1)), halt'
|
$ scryer-prolog -f --no-add-history -g 'use_module(library(process)), use_module(library(format)), process_create("cmd", [], [process(P), stdout(null), stdin(pipe(S))]), format(S, "exit 1~n", []), process_wait(P, exit(1)), halt'
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
existence error is expected as the process has been released, but the panic is unexpected see [issue 3300](https://github.com/mthom/scryer-prolog/issues/3300)
|
||||||
|
```trycmd
|
||||||
|
$ scryer-prolog -f --no-add-history -t halt -g 'use_module(library(process)), process_create("cmd", ["/C", "exit", "1"], [process(P)]), process_id(P, Pid), write(pid=Pid), nl, process_wait(P, exit(1)), process_id(P, Pid2), write(pid=Pid2), nl'
|
||||||
|
? failed
|
||||||
|
pid=[..]
|
||||||
|
use_module(library(process)),process_create("cmd",["/C","exit","1"],[process(P)]),process_id(P,Pid),write(pid=Pid),nl,process_wait(P,exit(1)),process_id(P,Pid2),write(pid=Pid2),nl causes: error(existence_error(process,$dropped_value),[predicate-process_id/2|process_id/2])
|
||||||
|
|
||||||
|
thread 'main' ([..]) panicked at src/machine/loader.rs:[..]:[..]:
|
||||||
|
called `Result::unwrap()` on an `Err` value: ()
|
||||||
|
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
existence error is expected as the process has been released, but the panic is unexpected see [issue 3300](https://github.com/mthom/scryer-prolog/issues/3300)
|
||||||
|
```trycmd
|
||||||
|
$ scryer-prolog -f --no-add-history -t halt -g 'use_module(library(process)), process_create("cmd", ["/C", "exit", "1"], [process(P)]), process_id(P, Pid), write(pid=Pid), nl, process_wait(P, exit(1), [release(false)]), process_id(P, Pid2), write(pid=Pid2), nl, process_release(P), process_id(P, Pid3), write(pid=Pid3), nl'
|
||||||
|
? failed
|
||||||
|
pid=[..]
|
||||||
|
pid=[..]
|
||||||
|
use_module(library(process)),process_create("cmd",["/C","exit","1"],[process(P)]),process_id(P,Pid),write(pid=Pid),nl,process_wait(P,exit(1),[release(false)]),process_id(P,Pid2),write(pid=Pid2),nl,process_release(P),process_id(P,Pid3),write(pid=Pid3),nl causes: error(existence_error(process,$dropped_value),[predicate-process_id/2|process_id/2])
|
||||||
|
|
||||||
|
thread 'main' ([..]) panicked at src/machine/loader.rs:[..]:[..]:
|
||||||
|
called `Result::unwrap()` on an `Err` value: ()
|
||||||
|
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
||||||
|
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user