-
Notifications
You must be signed in to change notification settings - Fork 174
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
system: subprocessing interface #911
Open
perazz
wants to merge
36
commits into
fortran-lang:master
Choose a base branch
from
perazz:subprocess
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cool addition! I always wanted to have something like this in the past. I wrote my own little experiment once. I started reviewing the Python subprocess module, but got discouraged by the messy implementation details. |
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 Pythonsubprocess
module.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
,stderr
as strings.run
a synchronous or asynchronous process:process = run(cmd [, wait=.true,] [, stdin=string] [, want_stdout=.false.] [, want_stderr=.false.])
update
query process state and update the state variable:call update(process)
is_running
check if a process is still running and update the handler:status = is_running(process)
is_completed
check if a process has finished and update the handler:status = is_completed(process)
wait
for completion (option for max waiting time in seconds):call wait(process [, max_wait_time=10.0])
elapsed
time since process start, or total process lifetime:duration = elapsed(process)
kill
a running external process:call kill(process, success)
sleep
implementation is moved to C so that a slightly better wrapper based onnanosecond
can be usedThis provides a concise overview of the interfaces for quick reference.
Key facts
interface
s 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
,stdin
are 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