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
Unthreadable aliases hang when piped from or to #5317
Comments
xunter tells me about the endless loop: xunter --no-rc -c "xonfig | head" ++depth-lt 20 xonsh/xonsh/procs/pipelines.py Lines 807 to 825 in 04cba39
Because By putting |
Catched this for xonfig and for xontribs: from xonsh.xonfig import XonfigAlias
aliases['xfg'] = XonfigAlias(threadable=True)
xfg | head
# Works as expected
aliases['xfg'] = XonfigAlias(threadable=False) # current behavior in `xonfig`
xfg | head
# Hanging (the cause described above)
from xonsh.xontribs import XontribAlias
aliases['xnt'] = XontribAlias(threadable=True)
xnt list | grep load
# No hanging but grep is not working - we need to understand why UPD: fixed in #5321 @gforsyth could you please comment why the aliases were marked as unthreadable? If you know or you can guess. @Qyriad I think we need to understand the cause of hanging and as minimum create sane exception for the situation that hangs the execution.
Thanks for looking around! I've closed the same issues. PS. Personally I would like to have a builtin tool to inspect the command pipeline (
OR improve It will help to debug the processes. |
Well outside of memory, I'm afraid. But if they are working now with I suspect some part of |
This comment was marked as resolved.
This comment was marked as resolved.
Fixed in #5321 |
Yes that could be an issue. Especially how it keeps hold of stdin/stdout variables passed to it. |
Hey @jnoortheen! You wrote in #5321 (comment):
Could you please describe the machinery and pros/cons of this approach? May be if this requires just a few lines of code we can play with it in the branch. |
The debug code reveals that , the default mode is being ![] instead of $[] . |
I debug this issue with this from pprint import pprint
from xonsh.built_ins import XSH
XSH.load()
from xonsh.procs.specs import cmds_to_specs, run_subproc
from xonsh.tools import unthreadable, uncapturable
# Default alias - threadable by default.
@XSH.aliases.register('def')
def a_def(args, i, o):
print('def', file=o)
# Unthreadable alias.
@XSH.aliases.register('unt')
@unthreadable
def a_unt(args, i, o):
print('unt', file=o)
cmd = [['def'], '|', ['head']] # This command is working well.
# cmd = [['unt'], '|', ['head']] # This command is hanging without execution.
# cmd = [['unt']] # This command executed well.
specs = cmds_to_specs(cmd, captured="stdout")
pprint([s.__dict__ for s in specs])
"""
https://github.com/xonsh/xonsh/blob/db83a3f35382b8f692c25d73740ddde11d5a17d3/xonsh/procs/specs.py#L314-L317
captured : bool or str, optional
The flag for if the subprocess is captured, may be one of:
False for $[], 'stdout' for $(), 'hiddenobject' for ![], or
'object' for !().
"""
r = run_subproc(cmd, captured="stdout")
print(r) I found that Line 690 in db83a3f
Line 762 in db83a3f
Line 351 in db83a3f
If we run threadable alias then But if we run unthredable alias in pipe than This is the cause why piping from unthreadable alias hang the execution. |
I'm not totally clear on the trigger conditions here, but the xonsh built-in commands that are unthreadable (xonfig, source, trace, fg) hang when piped to or from. However callable aliases that I've defined with
@xonsh.tools.unthreadable
don't seem to hang, so I'm not quite sure what's going on. Some builtins that don't hang include disown, which, source-foreign, showcmd, and bg.Neither
--no-rc
nor$THREAD_SUBPROCS
affect this behavior.xonfig
Expected Behavior
Commands like
echo foo | source
ortrace --help | rg .
should not hang.Current Behavior & Reproduction
In a checkout of the latest commit:
(Reproduces interactively or non-interactively).
Traceback
From within the shell, Ctrl-C does nothing, but if executed non-interactively as above, CtrlC produces the following traceback:
Any suggestions on places to start digging for this one?
For community
⬇️ Please click the 👍 reaction instead of leaving a
+1
or 👍 commentThe text was updated successfully, but these errors were encountered: