Suppress error message from sh for background process
xmnlab opened this issue · comments
Ivan Ogasawara commented
Hey everyone!
Is there a way to suppress the error message from sh
for background process?
if there is an error message from the process, this is something I want to show/print .. but not from the sh python traceback, for example, this is something that I don't want to show:
Exception in thread background thread for pid 323610:
Traceback (most recent call last):
File "/home/xmn/mambaforge/envs/makim/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/home/xmn/mambaforge/envs/makim/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/home/xmn/mambaforge/envs/makim/lib/python3.10/site-packages/sh.py", line 1641, in wrap
fn(*rgs, **kwargs)
File "/home/xmn/mambaforge/envs/makim/lib/python3.10/site-packages/sh.py", line 2569, in background_thread
handle_exit_code(exit_code)
File "/home/xmn/mambaforge/envs/makim/lib/python3.10/site-packages/sh.py", line 2269, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/xmn/mambaforge/envs/makim/lib/python3.10/site-packages/sh.py", line 869, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /usr/bin/bash -c 'pre-commit run --all-files --verbose'
STDOUT:
STDERR:
thanks
Ivan Ogasawara commented
additionally, I have already something like that:
try:
p.wait()
except sh.ErrorReturnCode:
...
except KeyboardInterrupt:
pid = p.pid
p.kill()
print(f'[WW] Process {pid} killed.')
Andrew commented
Is this what you're looking for? https://amoffat.github.io/sh/sections/special_arguments.html#bg-exc
Ivan Ogasawara commented
thank you so much! that fixed my problem. appreciate that!