Comments (4)
Don't have an answer to this unfortunately. Known issue: #489
Possible workaround: #326 (comment)
from pynvim.
A workaround is to use nest_asyncio. It is not a perfect solution as the behavior of nested asyncio loop can be quite unintuitive and strange, but works at least minimally:
[1]: import nest_asyncio
nest_asyncio.apply()
[2]: from pynvim import attach
nvim = attach('socket', path='/tmp/nvim.sock')
[3]: nvim.current.buffer[:] = 'foo'
from pynvim.
GH doesn't support uploading ipynb files, so here's the raw text of a minimal Jupyter notebook to reproduce the issue:
Expand me for the notebook
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"id": "5636335d",
"metadata": {
"ExecuteTime": {
"end_time": "2023-09-15T10:31:53.742817Z",
"start_time": "2023-09-15T10:31:42.902843Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: pynvim in /Users/brk/Library/Python/3.10/lib/python/site-packages (0.4.3)\n",
"Requirement already satisfied: msgpack>=0.5.0 in /Users/brk/Library/Python/3.10/lib/python/site-packages (from pynvim) (1.0.5)\n",
"Requirement already satisfied: greenlet in /Users/brk/Library/Python/3.10/lib/python/site-packages (from pynvim) (2.0.2)\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"!Make sure you start neovim listening with: `NVIM_LISTEN_ADDRESS=/tmp/nvim nvim`. Press any key to continue\n"
]
},
{
"ename": "RuntimeError",
"evalue": "Cannot run the event loop while another loop is running",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 4>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpynvim\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m attach\n\u001b[1;32m 3\u001b[0m blocker \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m!Make sure you start neovim listening with: `NVIM_LISTEN_ADDRESS=/tmp/nvim nvim`. Press any key to continue\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 4\u001b[0m nvim \u001b[38;5;241m=\u001b[39m \u001b[43mattach\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msocket\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpath\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m/tmp/nvim\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 5\u001b[0m nvim\u001b[38;5;241m.\u001b[39mcommand(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mvsplit\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"File \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/pynvim/__init__.py:111\u001b[0m, in \u001b[0;36mattach\u001b[0;34m(session_type, address, port, path, argv, decode)\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mattach\u001b[39m(session_type, address\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, port\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 81\u001b[0m path\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, argv\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, decode\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m 82\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Provide a nicer interface to create python api sessions.\u001b[39;00m\n\u001b[1;32m 83\u001b[0m \n\u001b[1;32m 84\u001b[0m \u001b[38;5;124;03m Previous machinery to create python api sessions is still there. This only\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 108\u001b[0m \n\u001b[1;32m 109\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[1;32m 110\u001b[0m session \u001b[38;5;241m=\u001b[39m (tcp_session(address, port) \u001b[38;5;28;01mif\u001b[39;00m session_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtcp\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m\n\u001b[0;32m--> 111\u001b[0m \u001b[43msocket_session\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpath\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mif\u001b[39;00m session_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msocket\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m\n\u001b[1;32m 112\u001b[0m stdio_session() \u001b[38;5;28;01mif\u001b[39;00m session_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mstdio\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m\n\u001b[1;32m 113\u001b[0m child_session(argv) \u001b[38;5;28;01mif\u001b[39;00m session_type \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mchild\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m\n\u001b[1;32m 114\u001b[0m \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[1;32m 116\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m session:\n\u001b[1;32m 117\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUnknown session type \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m%\u001b[39m session_type)\n",
"File \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/pynvim/msgpack_rpc/__init__.py:35\u001b[0m, in \u001b[0;36msocket_session\u001b[0;34m(path)\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msocket_session\u001b[39m(path):\n\u001b[1;32m 34\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Create a msgpack-rpc session from a unix domain socket.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 35\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43msession\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43msocket\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpath\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/pynvim/msgpack_rpc/__init__.py:19\u001b[0m, in \u001b[0;36msession\u001b[0;34m(transport_type, *args, **kwargs)\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msession\u001b[39m(transport_type\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mstdio\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[0;32m---> 19\u001b[0m loop \u001b[38;5;241m=\u001b[39m \u001b[43mEventLoop\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtransport_type\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 20\u001b[0m msgpack_stream \u001b[38;5;241m=\u001b[39m MsgpackStream(loop)\n\u001b[1;32m 21\u001b[0m async_session \u001b[38;5;241m=\u001b[39m AsyncSession(msgpack_stream)\n",
"File \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/pynvim/msgpack_rpc/event_loop/base.py:93\u001b[0m, in \u001b[0;36mBaseEventLoop.__init__\u001b[0;34m(self, transport_type, *args)\u001b[0m\n\u001b[1;32m 91\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 92\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclose()\n\u001b[0;32m---> 93\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m e\n\u001b[1;32m 94\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_start_reading()\n",
"File \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/pynvim/msgpack_rpc/event_loop/base.py:90\u001b[0m, in \u001b[0;36mBaseEventLoop.__init__\u001b[0;34m(self, transport_type, *args)\u001b[0m\n\u001b[1;32m 88\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_init()\n\u001b[1;32m 89\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m---> 90\u001b[0m \u001b[38;5;28;43mgetattr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m_connect_\u001b[39;49m\u001b[38;5;132;43;01m{}\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mformat\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtransport_type\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 91\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m 92\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mclose()\n",
"File \u001b[0;32m~/Library/Python/3.10/lib/python/site-packages/pynvim/msgpack_rpc/event_loop/asyncio.py:96\u001b[0m, in \u001b[0;36mAsyncioEventLoop._connect_socket\u001b[0;34m(self, path)\u001b[0m\n\u001b[1;32m 94\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 95\u001b[0m coroutine \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_loop\u001b[38;5;241m.\u001b[39mcreate_unix_connection(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_fact, path)\n\u001b[0;32m---> 96\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_loop\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_until_complete\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcoroutine\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py:622\u001b[0m, in \u001b[0;36mBaseEventLoop.run_until_complete\u001b[0;34m(self, future)\u001b[0m\n\u001b[1;32m 611\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Run until the Future is done.\u001b[39;00m\n\u001b[1;32m 612\u001b[0m \n\u001b[1;32m 613\u001b[0m \u001b[38;5;124;03mIf the argument is a coroutine, it is wrapped in a Task.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 619\u001b[0m \u001b[38;5;124;03mReturn the Future's result, or raise its exception.\u001b[39;00m\n\u001b[1;32m 620\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 621\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_closed()\n\u001b[0;32m--> 622\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_check_running\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 624\u001b[0m new_task \u001b[38;5;241m=\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m futures\u001b[38;5;241m.\u001b[39misfuture(future)\n\u001b[1;32m 625\u001b[0m future \u001b[38;5;241m=\u001b[39m tasks\u001b[38;5;241m.\u001b[39mensure_future(future, loop\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m)\n",
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py:584\u001b[0m, in \u001b[0;36mBaseEventLoop._check_running\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 582\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThis event loop is already running\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 583\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m events\u001b[38;5;241m.\u001b[39m_get_running_loop() \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 584\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\n\u001b[1;32m 585\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mCannot run the event loop while another loop is running\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
"\u001b[0;31mRuntimeError\u001b[0m: Cannot run the event loop while another loop is running"
]
}
],
"source": [
"%pip install pynvim\n",
"from pynvim import attach\n",
"blocker = input(\"!Make sure you start neovim listening with: `NVIM_LISTEN_ADDRESS=/tmp/nvim nvim`. Press any key to continue\")\n",
"nvim = attach('socket', path='/tmp/nvim')\n",
"nvim.command('vsplit')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
from pynvim.
Thanks for the swift reply
from pynvim.
Related Issues (20)
- `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
- 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
- test_vim: Failure with Python 3.13 HOT 1
- pytest-runner deprecated HOT 2
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.