Skip to content

Commit c784927

Browse files
committed
event_loop: enable asyncio on windows, needs Nvim 0.3.0+
Revert "event loop: disable asyncio on nt for now (#308)" This reverts commit 42b6e18.
1 parent 3777747 commit c784927

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

neovim/api/nvim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __init__(self, session, channel_id, metadata, types,
121121
self._err_cb = err_cb
122122

123123
# only on python3.4+ we expose asyncio
124-
if IS_PYTHON3 and os.name != 'nt':
124+
if IS_PYTHON3:
125125
self.loop = self._session.loop._loop
126126

127127
def _from_nvim(self, obj, decode=None):

neovim/msgpack_rpc/event_loop/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
Tries to use pyuv as a backend, falling back to the asyncio implementation.
44
"""
55

6-
import os
7-
86
from ...compat import IS_PYTHON3
97

108
# on python3 we only support asyncio, as we expose it to plugins
11-
if IS_PYTHON3 and os.name != 'nt':
9+
if IS_PYTHON3:
1210
from .asyncio import AsyncioEventLoop
1311
EventLoop = AsyncioEventLoop
1412
else:

neovim/msgpack_rpc/event_loop/asyncio.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111
from __future__ import absolute_import
1212

13+
import logging
1314
import os
1415
import sys
1516
from collections import deque
@@ -23,11 +24,17 @@
2324

2425
from .base import BaseEventLoop
2526

27+
logger = logging.getLogger(__name__)
28+
debug, info, warn = (logger.debug, logger.info, logger.warning,)
2629

2730
loop_cls = asyncio.SelectorEventLoop
2831
if os.name == 'nt':
32+
from asyncio.windows_utils import PipeHandle
33+
import msvcrt
34+
2935
# On windows use ProactorEventLoop which support pipes and is backed by the
3036
# more powerful IOCP facility
37+
# NOTE: we override in the stdio case, because it doesn't work.
3138
loop_cls = asyncio.ProactorEventLoop
3239

3340

@@ -89,14 +96,26 @@ def _connect_socket(self, path):
8996
self._loop.run_until_complete(coroutine)
9097

9198
def _connect_stdio(self):
92-
coroutine = self._loop.connect_read_pipe(self._fact, sys.stdin)
99+
if os.name == 'nt':
100+
pipe = PipeHandle(msvcrt.get_osfhandle(sys.stdin.fileno()))
101+
else:
102+
pipe = sys.stdin
103+
coroutine = self._loop.connect_read_pipe(self._fact, pipe)
93104
self._loop.run_until_complete(coroutine)
94-
coroutine = self._loop.connect_write_pipe(self._fact, sys.stdout)
105+
debug("native stdin connection successful")
106+
107+
if os.name == 'nt':
108+
pipe = PipeHandle(msvcrt.get_osfhandle(sys.stdout.fileno()))
109+
else:
110+
pipe = sys.stdout
111+
coroutine = self._loop.connect_write_pipe(self._fact, pipe)
95112
self._loop.run_until_complete(coroutine)
113+
debug("native stdout connection successful")
96114

97115
def _connect_child(self, argv):
98-
self._child_watcher = asyncio.get_child_watcher()
99-
self._child_watcher.attach_loop(self._loop)
116+
if os.name != 'nt':
117+
self._child_watcher = asyncio.get_child_watcher()
118+
self._child_watcher.attach_loop(self._loop)
100119
coroutine = self._loop.subprocess_exec(self._fact, *argv)
101120
self._loop.run_until_complete(coroutine)
102121

setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
'test': tests_require,
1818
}
1919

20-
if os.name == 'nt':
21-
install_requires.append('pyuv>=1.0.0')
22-
elif sys.version_info < (3, 4):
23-
# trollius is just a backport of 3.4 asyncio module
24-
install_requires.append('trollius')
20+
if sys.version_info < (3, 4):
21+
if os.name == 'nt':
22+
install_requires.append('pyuv>=1.0.0')
23+
else:
24+
# trollius is just a backport of 3.4 asyncio module
25+
install_requires.append('trollius')
2526

2627
if platform.python_implementation() != 'PyPy':
2728
# pypy already includes an implementation of the greenlet module

0 commit comments

Comments
 (0)