python-mpv-jsonipc icon indicating copy to clipboard operation
python-mpv-jsonipc copied to clipboard

Disconnecting...

Open vorgos opened this issue 3 years ago • 4 comments

I'm playing around and I can create a new instance of MPV or connect to an existing one just fine, but I am not sure how to disconnect once connected.

Looking at whats available, mpv.terminate() seems to be the right thing but now and again I get,

Socket connection died.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/python_mpv_jsonipc.py", line 168, in run
    current_data = self.socket.recv(1024)
OSError: [Errno 9] Bad file descriptor

How do I disconnect without an error?

vorgos avatar Sep 03 '21 11:09 vorgos

That error just tells you that the socket was disconnected. If you disconnect it then it’s expected.

iwalton3 avatar Sep 03 '21 11:09 iwalton3

Thanks. But why is it inconsistent? If I run it 5 times, it might error once.

Also, shouldn't wrapping mvp.terminate() in a try clause stop the error from being generated? It doesn't. (thought there might be something I am doing wrong given that I am new to Python)

vorgos avatar Sep 04 '21 04:09 vorgos

I'm not sure why the error is inconsistent. Usually the socket will return an empty string when it is closed but it seems like sometimes for you it is giving an exception. There is already a try-catch but it prints out the exception as it is considered unexpected. (Are you on Linux or some other platform? Maybe it's a platform-specific thing.)

iwalton3 avatar Sep 04 '21 04:09 iwalton3

I am working on a Ubuntu 21.04

I am just starting to play around at the moment. My code so far is connecting to the instance and disconnecting. I wanted to confirm what I was seeing before I continue.

Thanks.

vorgos avatar Sep 04 '21 06:09 vorgos