Skip to content

Commit

Permalink
event_loop: enable asyncio on windows, needs Nvim 0.3.0+
Browse files Browse the repository at this point in the history
Revert "event loop: disable asyncio on nt for now (#308)"

This reverts commit 42b6e18.
  • Loading branch information
bfredl committed Jul 15, 2018
1 parent 3777747 commit c784927
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion neovim/api/nvim.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(self, session, channel_id, metadata, types,
self._err_cb = err_cb

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

def _from_nvim(self, obj, decode=None):
Expand Down
4 changes: 1 addition & 3 deletions neovim/msgpack_rpc/event_loop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
Tries to use pyuv as a backend, falling back to the asyncio implementation.
"""

import os

from ...compat import IS_PYTHON3

# on python3 we only support asyncio, as we expose it to plugins
if IS_PYTHON3 and os.name != 'nt':
if IS_PYTHON3:
from .asyncio import AsyncioEventLoop
EventLoop = AsyncioEventLoop
else:
Expand Down
27 changes: 23 additions & 4 deletions neovim/msgpack_rpc/event_loop/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
from __future__ import absolute_import

import logging
import os
import sys
from collections import deque
Expand All @@ -23,11 +24,17 @@

from .base import BaseEventLoop

logger = logging.getLogger(__name__)
debug, info, warn = (logger.debug, logger.info, logger.warning,)

loop_cls = asyncio.SelectorEventLoop
if os.name == 'nt':
from asyncio.windows_utils import PipeHandle
import msvcrt

# On windows use ProactorEventLoop which support pipes and is backed by the
# more powerful IOCP facility
# NOTE: we override in the stdio case, because it doesn't work.
loop_cls = asyncio.ProactorEventLoop


Expand Down Expand Up @@ -89,14 +96,26 @@ def _connect_socket(self, path):
self._loop.run_until_complete(coroutine)

def _connect_stdio(self):
coroutine = self._loop.connect_read_pipe(self._fact, sys.stdin)
if os.name == 'nt':
pipe = PipeHandle(msvcrt.get_osfhandle(sys.stdin.fileno()))
else:
pipe = sys.stdin
coroutine = self._loop.connect_read_pipe(self._fact, pipe)
self._loop.run_until_complete(coroutine)
coroutine = self._loop.connect_write_pipe(self._fact, sys.stdout)
debug("native stdin connection successful")

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

def _connect_child(self, argv):
self._child_watcher = asyncio.get_child_watcher()
self._child_watcher.attach_loop(self._loop)
if os.name != 'nt':
self._child_watcher = asyncio.get_child_watcher()
self._child_watcher.attach_loop(self._loop)
coroutine = self._loop.subprocess_exec(self._fact, *argv)
self._loop.run_until_complete(coroutine)

Expand Down
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
'test': tests_require,
}

if os.name == 'nt':
install_requires.append('pyuv>=1.0.0')
elif sys.version_info < (3, 4):
# trollius is just a backport of 3.4 asyncio module
install_requires.append('trollius')
if sys.version_info < (3, 4):
if os.name == 'nt':
install_requires.append('pyuv>=1.0.0')
else:
# trollius is just a backport of 3.4 asyncio module
install_requires.append('trollius')

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

0 comments on commit c784927

Please sign in to comment.