WIP: basic coroutine and subprocess support#393
Conversation
|
I have tested it and it works. But nvim.run_coroutine(c)It must be |
|
I forgot to push the last fix. I also fixed stdin capability: |
|
Ah, OK. Thank you for the fix. |
|
Hm.... I have tested it. The sleep works, but in subprocess cannot access neovim until RPC is finished. |
Hm. This is needed. |
@Shougo What is the situation more specifically? If the parent python process is in a sync handler, the child cannot connect until the sync handler returns. |
|
In the branch The sample seems use nvim in only |
|
The subprocess can use nvim, but for now it has to connect on its own using |
Yes. But in |
|
This is a bit tricky, parent and child python cannot collectively "own" the nvim focus, only one channel can be blocking at a time. For now it has to be async. We can of course add this ability, but it will need more code in nvim core. |
Yes, ui branch uses async RPC. But it is not perfect.
OK. So I wait it. |
Work towards #342
The model supported here is: plugin code is written as greenlets ( spawned as request handlers or
nvim.async_call), but once in a while needs to invoke a coroutine defined by some library (such as asyncio itself). This model is enough is to use the io facilities of asyncio, which mostly uses raw callbacks.nvim.run_coroutine(coro)will spawn an asyncio task and suspend the current greenlet until completion and return the result. If you don't care about the result you can still use the non-blockingasyncio.ensure_future(coro).A simple example to suspend the current handler for some time (NB: will block nvim if the handler is
sync):As a convenience a wrapper for the subprocess protocol is also added, which wraps the data handler in a greenlet (so that it can use
nvimrequests):