Skip to content

Commit

Permalink
translate socket.timeout to TTransportException
Browse files Browse the repository at this point in the history
  • Loading branch information
aisk committed Jan 28, 2021
1 parent 108cca5 commit e448470
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion thriftpy2/transport/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def read(self, sz):
while True:
try:
buff = self.sock.recv(sz)
except socket.timeout:
addr = self.sock.getsockname()
typ = TTransportException.TIMED_OUT
msg = "Timeouted when read from %s" % str(addr)
raise TTransportException(type=typ, message=msg)
except socket.error as e:
if e.errno == errno.EINTR:
continue
Expand All @@ -133,7 +138,13 @@ def read(self, sz):
return buff

def write(self, buff):
self.sock.sendall(buff)
try:
self.sock.sendall(buff)
except socket.timeout:
addr = self.sock.getsockname()
typ = TTransportException.TIMED_OUT
msg = "Timeouted when write to %s" % str(addr)
raise TTransportException(type=typ, message=msg)

def flush(self):
pass
Expand Down

0 comments on commit e448470

Please sign in to comment.