14
14
import sys
15
15
from collections import deque
16
16
from signal import Signals
17
- from typing import Any , Callable , Deque , List
17
+ from typing import Any , Callable , Deque , List , Optional
18
18
19
19
from pynvim .msgpack_rpc .event_loop .base import BaseEventLoop
20
20
@@ -37,6 +37,8 @@ class AsyncioEventLoop(BaseEventLoop, asyncio.Protocol,
37
37
"""`BaseEventLoop` subclass that uses `asyncio` as a backend."""
38
38
39
39
_queued_data : Deque [bytes ]
40
+ if os .name != 'nt' :
41
+ _child_watcher : Optional ['asyncio.AbstractChildWatcher' ]
40
42
41
43
def connection_made (self , transport ):
42
44
"""Used to signal `asyncio.Protocol` of a successful connection."""
@@ -58,12 +60,17 @@ def data_received(self, data: bytes) -> None:
58
60
59
61
def pipe_connection_lost (self , fd , exc ):
60
62
"""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
61
67
self ._on_error (exc .args [0 ] if exc else 'EOF' )
62
68
63
69
def pipe_data_received (self , fd , data ):
64
70
"""Used to signal `asyncio.SubprocessProtocol` of incoming data."""
65
71
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 ))
67
74
elif self ._on_data :
68
75
self ._on_data (data )
69
76
else :
@@ -78,6 +85,7 @@ def _init(self) -> None:
78
85
self ._queued_data = deque ()
79
86
self ._fact = lambda : self
80
87
self ._raw_transport = None
88
+ self ._child_watcher = None
81
89
82
90
def _connect_tcp (self , address : str , port : int ) -> None :
83
91
coroutine = self ._loop .create_connection (self ._fact , address , port )
@@ -145,6 +153,9 @@ def _close(self) -> None:
145
153
if self ._raw_transport is not None :
146
154
self ._raw_transport .close ()
147
155
self ._loop .close ()
156
+ if self ._child_watcher is not None :
157
+ self ._child_watcher .close ()
158
+ self ._child_watcher = None
148
159
149
160
def _threadsafe_call (self , fn : Callable [[], Any ]) -> None :
150
161
self ._loop .call_soon_threadsafe (fn )
0 commit comments