neovim / pynvim

Python client and plugin host for Nvim
http://pynvim.readthedocs.io/en/latest/
Apache License 2.0
1.48k stars 118 forks source link

OSError: EOF when trying to run example code on Windows #505

Closed Toqozz closed 8 months ago

Toqozz commented 2 years ago

I'm trying to run the example code on the main page of the README, namely:

>>> from pynvim import attach
>>> nvim = attach('child', argv=["/bin/env", "nvim", "--embed", "--headless"])

But I get an error instead:

>>> from pynvim import attach
>>> nvim = attach('child', argv=['C:\\Users\\Toqoz\\Documents\\code\\neovim-test\\Neovim2\\bin\\nvim.exe', '--embed', '--headless'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Toqoz\AppData\Roaming\Python\Python39\site-packages\pynvim\__init__.py", line 122, in attach
    return Nvim.from_session(session).with_decode(decode)
  File "C:\Users\Toqoz\AppData\Roaming\Python\Python39\site-packages\pynvim\api\nvim.py", line 80, in from_session
    channel_id, metadata = session.request(b'nvim_get_api_info')
  File "C:\Users\Toqoz\AppData\Roaming\Python\Python39\site-packages\pynvim\msgpack_rpc\session.py", line 98, in request
    raise OSError('EOF')
OSError: EOF

Running the same thing from a script gives a bit more info, but I think it's irrelevant:

Traceback (most recent call last):
  File "C:\Users\Toqoz\Documents\code\neovim-test\something.py", line 4, in <module>
    nvim = attach('child', argv=['C:\\Users\\Toqoz\\Documents\\code\\neovim-test\\Neovim2\\bin\\nvim.exe', "--embed"])
  File "C:\Users\Toqoz\AppData\Roaming\Python\Python39\site-packages\pynvim\__init__.py", line 122, in attach
    return Nvim.from_session(session).with_decode(decode)
  File "C:\Users\Toqoz\AppData\Roaming\Python\Python39\site-packages\pynvim\api\nvim.py", line 80, in from_session
    channel_id, metadata = session.request(b'nvim_get_api_info')
  File "C:\Users\Toqoz\AppData\Roaming\Python\Python39\site-packages\pynvim\msgpack_rpc\session.py", line 98, in request
    raise OSError('EOF')
OSError: EOF
Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x00000254C7607D30>
Traceback (most recent call last):
  File "C:\Users\Toqoz\AppData\Local\Programs\Python\Python39\lib\asyncio\base_subprocess.py", line 126, in __del__
  File "C:\Users\Toqoz\AppData\Local\Programs\Python\Python39\lib\asyncio\base_subprocess.py", line 104, in close
  File "C:\Users\Toqoz\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 108, in close
  File "C:\Users\Toqoz\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 746, in call_soon
  File "C:\Users\Toqoz\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000254C7637670>
Traceback (most recent call last):
  File "C:\Users\Toqoz\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 115, in __del__
  File "C:\Users\Toqoz\AppData\Local\Programs\Python\Python39\lib\asyncio\proactor_events.py", line 79, in __repr__
  File "C:\Users\Toqoz\AppData\Local\Programs\Python\Python39\lib\asyncio\windows_utils.py", line 102, in fileno
ValueError: I/O operation on closed pipe

Any pointers? I've also tried connecting using a socket but that also behaves weirdly on Windows.

$ python -- version
Python 3.9.6
Shougo commented 2 years ago

The neovim is already running? I think it is not running.

Toqozz commented 2 years ago

I thought the purpose of this code was to launch neovim as a child process and attach to that.

If I launch neovim (externally, just by running it) and then run the code I get the same error.

Shougo commented 2 years ago

The backslash escape is needed in single quotes?

Toqozz commented 2 years ago

Seems like it...

  File "C:\Users\Toqoz\Documents\code\neovim-test\something.py", line 4
    nvim = attach('child', argv=['C:\Users\Toqoz\Documents\code\neovim-test\Neovim2\bin\nvim.exe', "--embed"])
                                                                                                 ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

I'm fairly sure it is finding nvim.exe since if you change the path you get a file not found error.

Shougo commented 2 years ago

Hm. You should enable log.

Shougo commented 2 years ago

Reproduced it on neovim 0.7 Windows version. It works on older neovim(0.5) or Linux neovim. So I think something is changed.

Unfortunately, pynvim is not maintained well. neovim maintainers want to use Lua language instead.

Note: if_python3 works well.

Toqozz commented 2 years ago

Ah, thanks for that. I'll look into getting something else working.

MacKinley commented 2 years ago

neovim 0.4.4 was the latest version I was able to pynvim to work well with. For context, I'm on windows trying to use the ActualVim plugin on Sublime Text 4.

kuripa commented 1 year ago

Any updates on this? Tried it using Neovim 0.9.0 but still doesnt work..

justinmk commented 11 months ago

Since CI (github actions) is online now, Windows CI jobs are showing similar failures (python 3.10, 3.11) :

test/test_buffer.py::test_options ERROR                                  [ 10%]
  Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x0000026941A645E0>
  Traceback (most recent call last):
    File "C:\hostedtoolcache\windows\Python\3.11.4\x64\Lib\asyncio\base_subprocess.py", line 126, in __del__
      self.close()
    File "C:\hostedtoolcache\windows\Python\3.11.4\x64\Lib\asyncio\base_subprocess.py", line 104, in close
      proto.pipe.close()
    File "C:\hostedtoolcache\windows\Python\3.11.4\x64\Lib\asyncio\proactor_events.py", line 109, in close
      self._loop.call_soon(self._call_connection_lost, None)
    File "C:\hostedtoolcache\windows\Python\3.11.4\x64\Lib\asyncio\base_events.py", line 761, in call_soon
      self._check_closed()
    File "C:\hostedtoolcache\windows\Python\3.11.4\x64\Lib\asyncio\base_events.py", line [51](https://github.com/neovim/pynvim/actions/runs/5559406058/jobs/10155486134#step:8:52)9, in _check_closed
  Error:     raise RuntimeError('Event loop is closed')
wookayin commented 8 months ago

neovim/neovim@c86d5fa (#11390) seems to be the culprit: stderr gets closed immediately and this causes the event loop to stop. See PR #543 for the fix.