[MonetDB-users] MonetDB Python client
Hello! I had a problem with Python client hanging up if MonetDB connection was closed unexpectedly. This happened for example, when I have passed a request that caused "ERROR = !Connection terminated" in mclient. Such things should not occur in a ideal life, but they do =( The problem was that socket.recv cannot handle this situation properly. The solution is to use select.select statement. I attach the diff to mapi2.py file that solves the problem. Regards, Alexey
Hi Alexey, On 27-06-2012 17:43:19 +0200, Alexey Mints wrote:
I had a problem with Python client hanging up if MonetDB connection was closed unexpectedly. This happened for example, when I have passed a request that caused "ERROR = !Connection terminated" in mclient. Such things should not occur in a ideal life, but they do =( The problem was that socket.recv cannot handle this situation properly. The solution is to use select.select statement. I attach the diff to mapi2.py file that solves the problem.
Thanks for the patch! It's a bit hard to read (please use unified diff next time, diff -u), but does it essentially bring the loop outside the try? Fabian 25d24 < import select 233,241c232,234 < try: < while count > 0: < ready_to_read = [] < while len(ready_to_read) == 0: < ready_to_read, _, _ = select.select([self.socket], [], [], 0) < if len(ready_to_read) > 0: < recv = ready_to_read[0].recv(bytes, flags) < if recv == '': < raise socket.error(_, 'Connection closed unexpectedly') ---
while count > 0: try: recv = self.socket.recv(bytes, flags)
243,246c236,239 < count -= len(recv) < result.write(recv) < except socket.error, error: < raise OperationalError(error[1]) ---
except socket.error, error: raise OperationalError(error[1]) count -= len(recv) result.write(recv)
participants (2)
-
Alexey Mints
-
Fabian Groffen