Skip to content

Commit 87351e1

Browse files
committed
Fix _interrupt in both event loop implementations
The `_interrupt()` method was broken in both event loop implementations(it was not stopping the event loop). This commit adds a test and fixes the bug.
1 parent 596ca14 commit 87351e1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

neovim/msgpack_rpc/event_loop/asyncio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ def _stop(self):
108108
self._loop.stop()
109109

110110
def _interrupt(self):
111-
self._loop.call_soon_threadsafe(asyncio.async,
112-
lambda: self._loop.stop())
111+
self._loop.call_soon_threadsafe(lambda: self.stop())
113112

114113
def _setup_signals(self, signals):
115114
self._signals = list(signals)

neovim/msgpack_rpc/event_loop/uv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class UvEventLoop(BaseEventLoop):
1212

1313
def _init(self):
1414
self._loop = pyuv.Loop()
15-
self._async = pyuv.Async(self._loop, lambda h: self._on_interrupt)
15+
self._async = pyuv.Async(self._loop, lambda h: self.stop())
1616
self._connection_error = None
1717
self._error_stream = None
1818

test/test_concurrency.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from random import random
33
from nose.tools import with_setup, eq_ as eq
44
from common import vim, cleanup
5-
from threading import Thread
5+
from threading import Thread, Timer
66

77

88
@with_setup(setup=cleanup)
@@ -22,3 +22,12 @@ def produce(i):
2222
custom_messages.append(vim.session.next_message())
2323

2424
eq(len(custom_messages), 50)
25+
26+
27+
@with_setup(setup=cleanup)
28+
def test_interrupt_from_another_thread():
29+
timer = Timer(0.5, lambda: vim.session.post('timeout'))
30+
timer.start()
31+
msg = vim.session.next_message()
32+
eq(msg[0], 'notification')
33+
eq(msg[1], 'timeout')

0 commit comments

Comments
 (0)