Cannot execute a vim command from a new asyncio task
See original GitHub issueTo reproduce: Start Neovim with NVIM_PYTHON_LOG_FILE set, and run these commands:
py3 async def foo(): vim.out_write('testing')
py3 import asyncio, vim; asyncio.ensure_future(foo())
Then look in the python log file (_script
suffix) and see:
2018-06-30 20:20:29,362 [ERROR @ base_events.py:default_exception_handler:1266] 31555 - Task exception was never retrieved
future: <Task finished coro=<foo() done, defined at <string>:1> exception=AttributeError("'NoneType' object has no attribute 'switch'",)>
Traceback (most recent call last):
File "<string>", line 1, in foo
File "/usr/local/lib/python3.6/site-packages/neovim/api/nvim.py", line 378, in out_write
return self.request('nvim_out_write', msg, **kwargs)
File "/usr/local/lib/python3.6/site-packages/neovim/api/nvim.py", line 170, in request
res = self._session.request(name, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/neovim/msgpack_rpc/session.py", line 91, in request
v = self._yielding_request(method, args)
File "/usr/local/lib/python3.6/site-packages/neovim/msgpack_rpc/session.py", line 160, in _yielding_request
return parent.switch()
AttributeError: 'NoneType' object has no attribute 'switch'
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Running a command Async in Neovim
You cannot run the built-in command :make asynchronously in Vim8 or NeoVim. You have to take the value of 'makeprg' and insert it...
Read more >python - I can't execute command inside vim but it can be ...
I solve the issue through set a default shell in terminal configuration. I don't know what is different between this and setting default ......
Read more >Execute external programs asynchronously under Windows
start is not helpful because you will not see the output. Vim's :!start command starts a single process and additional shell commands like...
Read more >Advanced Visual Studio Code for Python Developers
You can't edit terminal profiles in the settings UI, so you need to use the Preferences: Open Settings (JSON) command in the Command...
Read more >if_pyth.txt - Vim
In the case of :pyfile, the code to execute is the contents of the given file. Python commands cannot be used in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
nvim-managed greenlets and asyncio coroutines are like water and oil, they are incompatible event/async primitives that simply don’t mix: any attempt to “seamlessly” integrate them might fail in the first request stack/event handing situation that wasn’t explicitly considered.
What we could add is (1) a greenlet-callable function, that runs an asyncio coro/future until completion and then resumes the greenlet and (2) an awaitable function that suspends a coroutine and runs a closure as a greenlet until it completes and then resumes the coroutine. Though this will more or less be callback hell and thus have none of the benefits of either the stackful greenlet approach or the explicitly yieldable approach of asyncio coroutines.
Rather what I would imagine useful is to reimplement the python client using only asyncio and native coroutines and no greenlets, I suspect that will be a lot simpler than the exisiting multi-layer client: it will more or less be a library providing a
nvim
asyncio protocol for its native transports, and request awaitables for coroutines which asyncio otherwise manages by itself.Yes. It would need be a separate project from this. I wouldn’t even think “fork”, rather new codebase which can happen to borrow code from this where it makes sense. Starting from scratch with no regards of vim compatibility (which necessitates a sync-like interface backed by greenlets or similar) would give a lot more freedom for both simplicity and expressivity. For instance
call_atomic
could be exposed as a function converting multiple request awaitables to a single awaitable, while with this codebase to usecall_atomic
you must throw all existing abstractions above the raw API out through the window.