Comments (5)
I'm trying to integrate the nvim-client event handling with the event loop of IPython (for interactive testing/introspection of plugins). The simplest way would be to call next_message with a very low time-out
There's a push_message
function created exactly for this purpose: It may be called from other threads(running different event loops for example) to generate virtual messages. Here is an example.
You should also read the tkinter ui script, which gives an idea of how to feed another event loop.(To run you need neovim/neovim#781)
TimeoutError seems unfortunably not be defined in python2.x. Perhaps define neovim.TimeoutError when running in python2?
👍 Will fix this now
Before writing any significant amount of code that uses the python client, keep in mind that it is still alpha so some APIs will probably change. One task I already have in mind: rewrite it using twisted(for pypy support) and greenlets(for simplified concurrency while still keeping the familiar synchronous API)
Also, the vim object could perhaps expose the fd of the underlying connection, that way the client could easily be efficiently integrated into any existing eventloop (by registering vim.next_message as callback for incoming data on the fd). (At least for my case that would be simpler than running the neovim eventloop in a separate thread)
As I said, the push_message
can be used to run the event loop in another thread. you can run the next_message
loop in a background thread if ipython event loop must be ran on the main thread
from pynvim.
Thanks for the pointers. The next_message(timeout)
usage was only temporary to integrate with the IPython terminal application (which doesn't have a proper loop, I think they just monkey-patch libreadline into calling a specific pyfunc X times per secound) Soon I will only use the IPython remote execution protocol, which is designed for async operation and will be straightforward to integrate using the push_message
pattern.
I'm fully aware of the alpha status, in fact the main motivation was just to test the api and figuring out missing pieces. An IPython client is interesting in this stage I think, since it will implement async completion, live object introspection/documentation and other such "code intel" features. The fact that it almost is ready for real use for me and is much more responsive than vim-ipython (at least in my test cases) is just a pure bonus. (for instance it already supports async stdout and code completion). If this "alpha stage" api already enables this much, I can only imagine how awesome it is going to be when it is getting closer to "stable". 👍
from pynvim.
@bfredl After the refactor the library should be more stable(it is still should be considered alpha though, at least until I fill some gaps in nvim plugin handling).
I still need to write some high level documentation but here's some updates:
vim.push_message
is nowvim.session.post(event_name, args...)
.vim.next_message
is nowvim.session.next_message()
and it no longer receives a timeout. It should be easy to emulate a timeout by using a combination ofthreading.Timer
withvim.session.post
from pynvim.
The post
method was broken so the timeout emulation probably wasn't working when I posted the comment. Just pushed a fix and published to pypi, here's an example of how you can do it:
from threading import Timer
t = Timer(5, lambda: vim.session.post('timeout'))
t.start()
print vim.session.next_message()
from pynvim.
Thanks, will try this out later.
from pynvim.
Related Issues (20)
- import pynvim 'disables' logging globally HOT 1
- Can't install pynvim with pipx HOT 1
- `num_to_str` boolean check makes `Ultisnips` snippet engine laggy HOT 5
- pin install pynvim fails to build greenlet on windows HOT 1
- Test failures: "Event loop is closed" with Python 3.12, Fedora Linux HOT 6
- test_vim.py fails with Python 3.12 HOT 1
- Controlling neovim from jupyter notebook: "another loop is running" HOT 4
- Get error "no module named imp" with Python 3.12 HOT 8
- No longer works in Python 3.12 HOT 4
- `<abuf>` is wrong for `BufUnload` with hidden buffer HOT 2
- luaeval behavior: functions are silently returning `None` HOT 3
- docs (readthedocs) CI is failing HOT 4
- Output flooded with EventLoop related messages HOT 5
- checkhealth WARNING: Could not contact PyPI to get latest version HOT 8
- Python 3.8: TypeError: 'type' object is not subscriptable HOT 11
- Access output of lua commands HOT 3
- UpdateRemotePlugins not finding any specs HOT 1
- Synchronous call initiated through a response of an async call drops the results of the sync call. HOT 4
- simplify remote plugins
- How do you access the treesitter API via pynvim? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pynvim.