From 7e36dad82836c128a97dfbbf2c58dee7f3eab96b Mon Sep 17 00:00:00 2001 From: ebenera Date: Wed, 5 Sep 2018 15:04:01 +0200 Subject: [PATCH] FIX: handling KeyboardInterrupt: lower level closes the socket automaticly --- vxi11/vxi11.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/vxi11/vxi11.py b/vxi11/vxi11.py index 231582d..2d8d5e0 100644 --- a/vxi11/vxi11.py +++ b/vxi11/vxi11.py @@ -677,13 +677,17 @@ def write_raw(self, data): block = data[offset:offset+self.max_recv_size] - error, size = self.client.device_write( - self.link, - self._timeout_ms, - self._lock_timeout_ms, - flags, - block - ) + try: + error, size = self.client.device_write( + self.link, + self._timeout_ms, + self._lock_timeout_ms, + flags, + block + ) + except KeyboardInterrupt: + self.link = None + raise if error: raise Vxi11Exception(error, 'write') @@ -714,15 +718,19 @@ def read_raw(self, num=-1): read_data = bytearray() while reason & (RX_END | RX_CHR) == 0: - error, reason, data = self.client.device_read( - self.link, - read_len, - self._timeout_ms, - self._lock_timeout_ms, - flags, - term_char - ) - + try: + error, reason, data = self.client.device_read( + self.link, + read_len, + self._timeout_ms, + self._lock_timeout_ms, + flags, + term_char + ) + except KeyboardInterrupt: + self.link = None + raise + if error: raise Vxi11Exception(error, 'read')