Skip to content

Commit

Permalink
Handle EINTR in the index client
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed May 18, 2012
1 parent 90a6a5c commit 82a28f4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions acoustid/indexclient.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (C) 2011 Lukas Lalinsky
# Distributed under the MIT license, see the LICENSE file for details.

import errno
import socket
import select
import time
Expand Down Expand Up @@ -59,11 +60,25 @@ def _getline(self, timeout=None):
timeout = self.timeout
deadline = time.time() + timeout
while pos == -1:
ready_to_read, ready_to_write, in_error = select.select([self.sock], [], [self.sock], self.socket_timeout)
try:
ready_to_read, ready_to_write, in_error = select.select([self.sock], [], [self.sock], self.socket_timeout)
except OSError, e:
if e.errno == errno.EINTR:
continue
raise
if in_error:
raise IndexClientError("socket error")
if ready_to_read:
self._buffer += self.sock.recv(1024)
while True:
try:
data = self.sock.recv(1024)
except OSError, e:
if e.errno == errno.EINTR:
continue
raise
if not data:
break
self._buffer += data
pos = self._buffer.find(CRLF)
if time.time() > deadline:
raise IndexClientError("read timeout exceeded")
Expand Down

0 comments on commit 82a28f4

Please sign in to comment.