1414import sys
1515from collections import deque
1616from signal import Signals
17- from typing import Any , Callable , Deque , List
17+ from typing import Any , Callable , Deque , List , Optional
1818
1919from pynvim .msgpack_rpc .event_loop .base import BaseEventLoop
2020
@@ -37,6 +37,8 @@ class AsyncioEventLoop(BaseEventLoop, asyncio.Protocol,
3737 """`BaseEventLoop` subclass that uses `asyncio` as a backend."""
3838
3939 _queued_data : Deque [bytes ]
40+ if os .name != 'nt' :
41+ _child_watcher : Optional ['asyncio.AbstractChildWatcher' ]
4042
4143 def connection_made (self , transport ):
4244 """Used to signal `asyncio.Protocol` of a successful connection."""
@@ -58,12 +60,17 @@ def data_received(self, data: bytes) -> None:
5860
5961 def pipe_connection_lost (self , fd , exc ):
6062 """Used to signal `asyncio.SubprocessProtocol` of a lost connection."""
63+ debug ("pipe_connection_lost: fd = %s, exc = %s" , fd , exc )
64+ if os .name == 'nt' and fd == 2 : # stderr
65+ # On windows, ignore piped stderr being closed immediately (#505)
66+ return
6167 self ._on_error (exc .args [0 ] if exc else 'EOF' )
6268
6369 def pipe_data_received (self , fd , data ):
6470 """Used to signal `asyncio.SubprocessProtocol` of incoming data."""
6571 if fd == 2 : # stderr fd number
66- self ._on_stderr (data )
72+ # Ignore stderr message, log only for debugging
73+ debug ("stderr: %s" , str (data ))
6774 elif self ._on_data :
6875 self ._on_data (data )
6976 else :
@@ -78,6 +85,7 @@ def _init(self) -> None:
7885 self ._queued_data = deque ()
7986 self ._fact = lambda : self
8087 self ._raw_transport = None
88+ self ._child_watcher = None
8189
8290 def _connect_tcp (self , address : str , port : int ) -> None :
8391 coroutine = self ._loop .create_connection (self ._fact , address , port )
@@ -145,6 +153,9 @@ def _close(self) -> None:
145153 if self ._raw_transport is not None :
146154 self ._raw_transport .close ()
147155 self ._loop .close ()
156+ if self ._child_watcher is not None :
157+ self ._child_watcher .close ()
158+ self ._child_watcher = None
148159
149160 def _threadsafe_call (self , fn : Callable [[], Any ]) -> None :
150161 self ._loop .call_soon_threadsafe (fn )
0 commit comments