-
Notifications
You must be signed in to change notification settings - Fork 151
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
Log subprocess input and output #4497
Conversation
@@ -37,7 +37,7 @@ def compile_kllvm(target_dir: str | Path, *, verbose: bool = False) -> Path: | |||
args += ['--verbose'] | |||
|
|||
_LOGGER.info(f'Compiling pythonast extension: {module_file.name}') | |||
run_process(args, logger=_LOGGER) | |||
run_process_2(args, logger=_LOGGER) |
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.
Breaking change: stderr
is not written.
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.
New output:
In [0]: compile_kllvm('.', verbose=True)
INFO:pyk.kllvm.compiler:Compiling pythonast extension: _kllvm.cpython-310-x86_64-linux-gnu.so
INFO:pyk.kllvm.compiler:[PID=752090][exec] llvm-kompile pythonast --python /home/ttoth/.cache/pypoetry/virtualenvs/kframework-8Tiaz0lD-py3.10/bin/python --python-output-dir /home/ttoth/git/k/pyk --verbose
INFO:pyk.kllvm.compiler:[PID=752090][stde] + /home/ttoth/git/k/k-distribution/bin/llvm-kompile-clang python_ast nolto -fno-stack-protector -v /home/ttoth/git/k/k-distribution/target/release/k/lib/kllvm/python_src/ast.cpp --python /home/ttoth/.cache/pypoetry/virtualenvs/kframework-8Tiaz0lD-py3.10/bin/python -fuse-ld=lld --python-output-dir /home/ttoth/git/k/pyk
INFO:pyk.kllvm.compiler:[PID=752090][stde] | + /usr/bin/clang++-15 -Wno-override-module -Wno-return-type-c-linkage /home/ttoth/git/k/k-distribution/bin/../lib/kllvm//libParser.a /home/ttoth/git/k/k-distribution/bin/../lib/kllvm//libAST.a /home/ttoth/git/k/k-distribution/bin/../lib/kllvm//libBinaryKore.a -Wl,-u,table_getArgumentSortsForTag -fPIC -shared -I/home/ttoth/git/k/k-distribution/bin/../include/ -fvisibility=hidden -I/home/ttoth/.pyenv/versions/3.10.13/include/python3.10 -I/home/ttoth/.cache/pypoetry/virtualenvs/kframework-8Tiaz0lD-py3.10/lib/python3.10/site-packages/pybind11/include -o /home/ttoth/git/k/pyk/_kllvm.cpython-310-x86_64-linux-gnu.so -ltinfo -lgmp -lgmpxx -lmpfr -lpthread -ldl -lffi -lunwind -I /home/ttoth/git/k/k-distribution/bin/../include/kllvm -I /home/ttoth/git/k/k-distribution/bin/../include --std=c++17 -fno-stack-protector /home/ttoth/git/k/k-distribution/target/release/k/lib/kllvm/python_src/ast.cpp -fuse-ld=lld
INFO:pyk.kllvm.compiler:[PID=752090][done] status=0 time=5.866s
Out[0]: PosixPath('/home/ttoth/git/k/pyk/_kllvm.cpython-310-x86_64-linux-gnu.so')
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.
Old output:
In [0]: compile_kllvm('.', verbose=True)
INFO:pyk.kllvm.compiler:Compiling pythonast extension: _kllvm.cpython-310-x86_64-linux-gnu.so
INFO:pyk.kllvm.compiler:Running: llvm-kompile pythonast --python /home/ttoth/.cache/pypoetry/virtualenvs/kframework-8Tiaz0lD-py3.10/bin/python --python-output-dir /home/ttoth/git/k/pyk --verbose
+ /home/ttoth/git/k/k-distribution/bin/llvm-kompile-clang python_ast nolto -fno-stack-protector -v /home/ttoth/git/k/k-distribution/target/release/k/lib/kllvm/python_src/ast.cpp --python /home/ttoth/.cache/pypoetry/virtualenvs/kframework-8Tiaz0lD-py3.10/bin/python -fuse-ld=lld --python-output-dir /home/ttoth/git/k/pyk
| + /usr/bin/clang++-15 -Wno-override-module -Wno-return-type-c-linkage /home/ttoth/git/k/k-distribution/bin/../lib/kllvm//libParser.a /home/ttoth/git/k/k-distribution/bin/../lib/kllvm//libAST.a /home/ttoth/git/k/k-distribution/bin/../lib/kllvm//libBinaryKore.a -Wl,-u,table_getArgumentSortsForTag -fPIC -shared -I/home/ttoth/git/k/k-distribution/bin/../include/ -fvisibility=hidden -I/home/ttoth/.pyenv/versions/3.10.13/include/python3.10 -I/home/ttoth/.cache/pypoetry/virtualenvs/kframework-8Tiaz0lD-py3.10/lib/python3.10/site-packages/pybind11/include -o /home/ttoth/git/k/pyk/_kllvm.cpython-310-x86_64-linux-gnu.so -ltinfo -lgmp -lgmpxx -lmpfr -lpthread -ldl -lffi -lunwind -I /home/ttoth/git/k/k-distribution/bin/../include/kllvm -I /home/ttoth/git/k/k-distribution/bin/../include --std=c++17 -fno-stack-protector /home/ttoth/git/k/k-distribution/target/release/k/lib/kllvm/python_src/ast.cpp -fuse-ld=lld
INFO:pyk.kllvm.compiler:Completed in 5.706s with status 0: llvm-kompile pythonast --python /home/ttoth/.cache/pypoetry/virtualenvs/kframework-8Tiaz0lD-py3.10/bin/python --python-output-dir /home/ttoth/git/k/pyk --verbose
Out[0]: PosixPath('/home/ttoth/git/k/pyk/_kllvm.cpython-310-x86_64-linux-gnu.so')
@@ -87,7 +87,7 @@ def compile_runtime( | |||
args += ccopts | |||
|
|||
_LOGGER.info(f'Compiling python extension: {module_file.name}') | |||
run_process(args, logger=_LOGGER) | |||
run_process_2(args, logger=_LOGGER) |
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.
Breaking change: stderr
is not written.
@@ -123,7 +123,7 @@ def generate_hints( | |||
|
|||
args = [str(interpreter), str(input_kore_file), '-1', str(hints_file), '--proof-output'] | |||
_LOGGER.info(f'Generating hints: {hints_file.name}') | |||
run_process(args, logger=_LOGGER) | |||
run_process_2(args, logger=_LOGGER) |
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.
Breaking change: stderr
is not written.
@@ -12,7 +12,7 @@ | |||
|
|||
def get_kllvm() -> Path: | |||
args = ['llvm-kompile', '--bindings-path'] | |||
proc = run_process(args, pipe_stdout=True) | |||
proc = run_process_2(args) |
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.
Breaking change: stderr
is not written.
@@ -79,5 +79,5 @@ def _kore_print( | |||
if color is not None: | |||
args += ['--color', 'on' if color else 'off'] | |||
|
|||
run_res = run_process(args, input=input) | |||
run_res = run_process_2(args, input=input) |
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.
Breaking change: stderr
is not written.
ff2a3ae
to
4bafaaf
Compare
@dwightguth, this PR introduces some breaking changes in the |
I presume we'll want to eventually deprecate the old |
Exactly. |
3e6eded
to
c73fd15
Compare
ab0f045
to
722e4f1
Compare
This PR implements a helper function,
run_process_2
, that modifies the behavior ofrun_process
in the following details:run_process_2
does not stream tostderr
(write_stderr=False
) by default.run_process
streams tostderr
(pipe_stderr=False
) by default.run_process_2
does not allow the called process to inherit the parent'sstdin
.run_process_2
logsstdin
,stderr
,stdout
of the called process.run_process_2
writes the PID with each log entry to correlate entries belonging to the same process.run_process_2
logs if an exception is raised during the process (e.g. aKeyboardInterrupt
).run_process_2
has a more succinct and more structured log output.run_process_2
always returns aCompletedProcess
withstdout
andstderr
set.run_process
only returns a non-None
value ifPIPE
is passed for the corresponding argument.These changes enable better integration of external tools into an application without compromising on debuggability (i.e. all information is logged but the caller's output streams are not polluted by the callee).
Example: log.txt