Merge pull request #2180 from xonsh/ppunth

proc proxy aliases
This commit is contained in:
Hugo Wang 2017-02-12 09:57:00 +08:00 committed by GitHub
commit 72a4cef947
3 changed files with 34 additions and 2 deletions

14
news/ppunth.rst Normal file
View file

@ -0,0 +1,14 @@
**Added:** None
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:**
* The ``ProcProxy`` class (unthreadable aliases) was not being executed and would
hange if the alias was capturable. This has been fixed.
**Security:** None

View file

@ -146,6 +146,17 @@ with open('tttt', 'w') as fp:
![cat tttt | wc | wc] ![cat tttt | wc | wc]
""", ' 1 3 24\n' if ON_WINDOWS else " 1 4 16 <stdin>\n", 0), """, ' 1 3 24\n' if ON_WINDOWS else " 1 4 16 <stdin>\n", 0),
# test unthreadable alias (which should trigger a ProcPoxy call)
("""
from xonsh.proc import unthreadable
@unthreadable
def _f():
return 'hello\\n'
aliases['f'] = _f
f
""", "hello\n", 0),
] ]

View file

@ -1734,7 +1734,8 @@ class CommandPipeline:
stdout = stdout.buffer stdout = stdout.buffer
if stdout is not None and not isinstance(stdout, self.nonblocking): if stdout is not None and not isinstance(stdout, self.nonblocking):
stdout = NonBlockingFDReader(stdout.fileno(), timeout=timeout) stdout = NonBlockingFDReader(stdout.fileno(), timeout=timeout)
if not stdout or self.captured == 'stdout' or not safe_readable(stdout): if not stdout or self.captured == 'stdout' or not safe_readable(stdout) or \
not spec.threadable:
# we get here if the process is not threadable or the # we get here if the process is not threadable or the
# class is the real Popen # class is the real Popen
PrevProcCloser(pipeline=self) PrevProcCloser(pipeline=self)
@ -1744,6 +1745,11 @@ class CommandPipeline:
self._endtime() self._endtime()
if self.captured == 'object': if self.captured == 'object':
self.end(tee_output=False) self.end(tee_output=False)
elif self.captured == 'hiddenobject' and stdout:
b = stdout.read()
lines = b.splitlines(keepends=True)
yield from lines
self.end(tee_output=False)
elif self.captured == 'stdout': elif self.captured == 'stdout':
b = stdout.read() b = stdout.read()
s = self._decode_uninew(b, universal_newlines=True) s = self._decode_uninew(b, universal_newlines=True)
@ -1831,7 +1837,8 @@ class CommandPipeline:
def tee_stdout(self): def tee_stdout(self):
"""Writes the process stdout to the output variable, line-by-line, and """Writes the process stdout to the output variable, line-by-line, and
yields each line. yields each line. This may optionally accept lines (in bytes) to iterate
over, in which case it does not call iterraw().
""" """
env = builtins.__xonsh_env__ env = builtins.__xonsh_env__
enc = env.get('XONSH_ENCODING') enc = env.get('XONSH_ENCODING')