Skip to content
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

print_exception and threaded alias: no traceback on second run #5408

Open
anki-code opened this issue May 12, 2024 · 0 comments · May be fixed by #5407
Open

print_exception and threaded alias: no traceback on second run #5408

anki-code opened this issue May 12, 2024 · 0 comments · May be fixed by #5407

Comments

@anki-code
Copy link
Member

I found weird artifact related to this PR during work on #5366.
Minimal repeatable example:

# docker run --rm -it xonsh/xonsh:slim xonsh

xonfig
# xonsh 0.14.0, python 3.11

$RAISE_SUBPROC_ERROR = False
$XONSH_SHOW_TRACEBACK = False
from xonsh.tools import print_exception
def _f():
    try:
       1/0
    except:
       print_exception(f"Exception")
aliases['f'] = _f

f
# ZeroDivisionError: division by zero
# Exception

f
# <----------------- Empty!

f
# ZeroDivisionError: division by zero
# Exception

After diving into why the second stderr output is forever empty I see that if I remove this line from print_exception() everything is good:

xonsh/xonsh/tools.py

Lines 1056 to 1058 in 55b341d

sys.last_type, sys.last_value, sys.last_traceback = exc_info

If this line is working I see that only on the second run of alias the stderr descriptor raises silent error on flushing:

safe_flush(sp_stderr)

def safe_flush(handle):
"""Attempts to safely flush a file handle, returns success bool."""
status = True
try:
handle.flush()
except OSError:
status = False
return status

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant