Skip to content

Commit

Permalink
asyncio: rename stdout fd in stdio mode
Browse files Browse the repository at this point in the history
so that print() and subprocess stdout doesn't interfere with RPC
  • Loading branch information
bfredl committed Jan 20, 2019
1 parent f609c0c commit 14ab154
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pynvim/msgpack_rpc/event_loop/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@ def _connect_stdio(self):
self._loop.run_until_complete(coroutine)
debug("native stdin connection successful")

# Make sure subprocesses don't clobber stdout,
# send the output to stderr instead.
rename_stdout = os.dup(sys.stdout.fileno())
os.dup2(sys.stderr.fileno(), sys.stdout.fileno())

if os.name == 'nt':
pipe = PipeHandle(msvcrt.get_osfhandle(sys.stdout.fileno()))
pipe = PipeHandle(msvcrt.get_osfhandle(rename_stdout))
else:
pipe = sys.stdout
pipe = os.fdopen(rename_stdout, 'wb')
coroutine = self._loop.connect_write_pipe(self._fact, pipe)
self._loop.run_until_complete(coroutine)
debug("native stdout connection successful")
Expand Down

0 comments on commit 14ab154

Please sign in to comment.