-
Notifications
You must be signed in to change notification settings - Fork 202
system: subprocessing interface #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I believe all community-requested features have been introduced. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR @perazz . Very valuable additions.
It could be helpful if the changes in stdlib_strings would have its own PR. It would be easier to review, and I believe it could be merged sooner. But it is also ok like this for me.
Co-authored-by: Jeremie Vandenplas <[email protected]>
Co-authored-by: Jeremie Vandenplas <[email protected]>
jvdp1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for this PR.
|
Merging due to no further comments. |
With this PR I want to introduce for discussion a comprehensive API for managing external processes in Fortran.
This is a fully cross-platform implementation for synchronous (similar to
execute_command_line) or asynchronous (fully detached process) processes, and mimics functionality from the Pythonsubprocessmodule.Previous discussion
Proposed API
Here’s the simplified list of interfaces with their types and example usage:
type(process_type): A derived type representing the external process state containing the state handler as well asstdin,stdout,stderras strings.runa synchronous (blocking) process:process = run(cmd [, stdin=string] [, want_stdout=.false.] [, want_stderr=.false.])runasyncan asynchronous (non-blocking) process:process = runasync(cmd [, stdin=string] [, want_stdout=.false.] [, want_stderr=.false.])updatequery process state and update the state variable:call update(process)is_runningcheck if a process is still running and update the handler:status = is_running(process)is_completedcheck if a process has finished and update the handler:status = is_completed(process)waitfor completion (option for max waiting time in seconds):call wait(process [, max_wait_time=10.0])elapsedtime since process start, or total process lifetime:duration = elapsed(process)killa running external process:call kill(process, success)sleepimplementation is moved to C so that a slightly better wrapper based onnanosecondcan be usedThis provides a concise overview of the interfaces for quick reference.
Key facts
interfaces are used rather than type-bound procedures because that seems more similar to the other stdlib interfaces, but I'm happy to introduce them as well and further discuss the API.stderr,stdout,stdinare stored via temporary files, but that is completely internal to the implementation. So, we can later implement faster memory-only communication via pipes without changing the API.type(state_type)general error handler is approved, we can improve this and use it throughout the subprocessing API too.Prior art