pynvim icon indicating copy to clipboard operation
pynvim copied to clipboard

OSError: EOF when trying to run example code on Windows

Open Toqozz opened this issue 2 years ago • 8 comments

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

Toqozz avatar Apr 11 '22 09:04 Toqozz

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

Shougo avatar Apr 11 '22 23:04 Shougo

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.

Toqozz avatar Apr 12 '22 08:04 Toqozz

The backslash escape is needed in single quotes?

Shougo avatar Apr 12 '22 08:04 Shougo

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.

Toqozz avatar Apr 12 '22 09:04 Toqozz

Hm. You should enable log.

Shougo avatar Apr 12 '22 12:04 Shougo

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.

Shougo avatar Apr 17 '22 03:04 Shougo

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

Toqozz avatar Apr 17 '22 07:04 Toqozz

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.

MacKinley avatar May 18 '22 20:05 MacKinley

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

kuripa avatar Mar 25 '23 11:03 kuripa

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')

justinmk avatar Jul 15 '23 11:07 justinmk

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.

wookayin avatar Oct 15 '23 01:10 wookayin