Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions python_mpv_jsonipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, ipc_socket, callback=None, quit_callback=None):
ipc_socket = "\\\\.\\pipe\\" + ipc_socket
self.callback = callback
self.quit_callback = quit_callback
self._stopping = False

access = _winapi.GENERIC_READ | _winapi.GENERIC_WRITE
limit = 5 # Connection may fail at first. Try 5 times.
Expand All @@ -75,6 +76,7 @@ def __init__(self, ipc_socket, callback=None, quit_callback=None):

def stop(self, join=True):
"""Terminate the thread."""
self._stopping = True
if self.socket is not None:
try:
self.socket.close()
Expand Down Expand Up @@ -116,7 +118,9 @@ def run(self):
if self.quit_callback:
self.quit_callback()
except Exception as ex:
log.error("Pipe connection died.", exc_info=1)
# Only log if not intentionally stopping
if not self._stopping:
log.error("Pipe connection died.", exc_info=1)
if self.quit_callback:
self.quit_callback()

Expand All @@ -137,6 +141,7 @@ def __init__(self, ipc_socket, callback=None, quit_callback=None):
self.ipc_socket = ipc_socket
self.callback = callback
self.quit_callback = quit_callback
self._stopping = False
self.socket = socket.socket(socket.AF_UNIX)
self.socket.connect(self.ipc_socket)

Expand All @@ -147,6 +152,7 @@ def __init__(self, ipc_socket, callback=None, quit_callback=None):

def stop(self, join=True):
"""Terminate the thread."""
self._stopping = True
if self.socket is not None:
try:
self.socket.shutdown(socket.SHUT_WR)
Expand Down Expand Up @@ -184,7 +190,9 @@ def run(self):
self.callback(json_data)
data = b''
except Exception as ex:
log.error("Socket connection died.", exc_info=1)
# Only log if not intentionally stopping
if not self._stopping:
log.error("Socket connection died.", exc_info=1)
if self.quit_callback:
self.quit_callback()

Expand Down