-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
Milestone
Description
It looks like the output redirection for CliRunner doesn't play nicely with Python's faulthandler library, as it terminates prematurely with the following backtrace (slightly modified to hide local filesystem details):
Traceback (most recent call last):
File "$CONDA_PREFIX/lib/python3.11/site-packages/click/testing.py", line 408, in invoke
return_value = cli.main(args=args or (), prog_name=prog_name, **extra)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "$CONDA_PREFIX/lib/python3.11/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "$CONDA_PREFIX/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "$CONDA_PREFIX/lib/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "./test_click.py", line 12, in main
faulthandler.enable()
io.UnsupportedOperation: filenoCode for test_click.py that replicates the problem:
import click
from click.testing import CliRunner
import faulthandler
import traceback
@click.command()
@click.option('--flag', type=bool, default=True)
def main(flag):
print("Executing main function...")
if flag:
print("Registering faulthandler")
faulthandler.enable()
print("Finished executing main function.")
if __name__ == '__main__':
flag_value = True
runner = CliRunner()
result = runner.invoke(main, ["--flag", flag_value])
print("Exit code = %d; contents of stdout:\n%s" % (result.exit_code, result.stdout))
if result.exit_code != 0:
traceback.print_exception(result.exc_info[1])The code was then executed by running python test_click.py
I assume the problem is that the CliRunner redirected stderr doesn't implement some details that are required by the faulthandler signal handler registration. Ideally, it should just work; or at least, it should avoid crashing and just do nothing (and perhaps be documented somewhere).
Environment:
- Python version: 3.11.10
- Click version: 8.1.7
Reactions are currently unavailable