mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
Catch SystemExit in ProcProxy (#5698)
* catch SystemExit in ProcProxy * add test * add news * update test * Update fix-procproxy-sys-exit.rst --------- Co-authored-by: Andy Kipp <anki-code@users.noreply.github.com>
This commit is contained in:
parent
4fc7d59c95
commit
79b3561c21
3 changed files with 43 additions and 0 deletions
23
news/fix-procproxy-sys-exit.rst
Normal file
23
news/fix-procproxy-sys-exit.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* Now SystemExit that invoked from callable alias follows to exiting from callable alias instead of exiting the entire shell.
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Built-in commands such as `xonfig -h` and `xontrib -h` no longer cause the shell to exit.
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -329,6 +329,22 @@ f
|
|||
"hello\n",
|
||||
0,
|
||||
),
|
||||
# test system exit in unthreadable alias (see #5689)
|
||||
(
|
||||
"""
|
||||
from xonsh.tools import unthreadable
|
||||
|
||||
@unthreadable
|
||||
def _f():
|
||||
import sys
|
||||
sys.exit(42)
|
||||
|
||||
aliases['f'] = _f
|
||||
print(![f].returncode)
|
||||
""",
|
||||
"42\n",
|
||||
0,
|
||||
),
|
||||
# test ambiguous globs
|
||||
(
|
||||
"""
|
||||
|
|
|
@ -792,6 +792,10 @@ class ProcProxy:
|
|||
"stack": spec.stack,
|
||||
},
|
||||
)
|
||||
except SystemExit as e:
|
||||
# the alias function is running in the main thread, so we need to
|
||||
# catch SystemExit to prevent the entire shell from exiting (see #5689)
|
||||
r = e.code if isinstance(e.code, int) else int(bool(e.code))
|
||||
except Exception:
|
||||
xt.print_exception(source_msg="Exception in " + get_proc_proxy_name(self))
|
||||
r = 1
|
||||
|
|
Loading…
Add table
Reference in a new issue