Vadim Yanitskiy has uploaded this change for review. ( 
https://gerrit.osmocom.org/11158


Change subject: mncc_sock.py: throw / raise exceptions from MnccSocket
......................................................................

mncc_sock.py: throw / raise exceptions from MnccSocket

Calling sys.exit() from MnccSocket's constructor could lead to
a situation when the main thread becomes "dead", while its child
threads are still working. Let's throw the exceptions towards
the caller, so it would be possible to handle them there.

Change-Id: I485eb86c69e74693eeae89723de27e376585f1da
---
M mncc_sock.py
1 file changed, 4 insertions(+), 12 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/mncc-python refs/changes/58/11158/1

diff --git a/mncc_sock.py b/mncc_sock.py
index e71a39a..0a64a81 100644
--- a/mncc_sock.py
+++ b/mncc_sock.py
@@ -10,7 +10,6 @@
 # option, any later version.

 import socket
-import sys
 import os
 import mncc
 import ctypes
@@ -122,11 +121,7 @@
         super(MnccSocketBase, self).__init__()
         self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
         print('connecting to %s' % address)
-        try:
-            self.sock.connect(address)
-        except socket.error as errmsg:
-            sys.stderr.write("%s\n" % errmsg)
-            sys.exit(1)
+        self.sock.connect(address)

         # Check the HELLO message
         self.check_hello()
@@ -137,15 +132,13 @@

         # Match expected message type
         if msg.msg_type != mncc.MNCC_SOCKET_HELLO:
-            sys.stderr.write('Received an unknown (!= MNCC_SOCKET_HELLO) '
+            raise AssertionError('Received an unknown (!= MNCC_SOCKET_HELLO) '
                 'message: %s\n' % msg)
-            sys.exit(1)

         # Match expected protocol version
         if msg.version != mncc.MNCC_SOCK_VERSION:
-            sys.stderr.write('MNCC protocol version mismatch '
+            raise AssertionError('MNCC protocol version mismatch '
                 '(0x%04x vs 0x%04x)\n' % (msg.version, mncc.MNCC_SOCK_VERSION))
-            sys.exit(1)

         # Match expected message sizes / offsets
         if (msg.mncc_size != ctypes.sizeof(mncc.gsm_mncc) or
@@ -154,8 +147,7 @@
             msg.signal_offset != mncc.gsm_mncc.signal.offset or
             msg.emergency_offset != mncc.gsm_mncc.emergency.offset or
             msg.lchan_type_offset != mncc.gsm_mncc.lchan_type.offset):
-                sys.stderr.write('MNCC message alignment mismatch\n')
-                sys.exit(1)
+                raise AssertionError('MNCC message alignment mismatch\n')

         print('Received %s' % msg)


--
To view, visit https://gerrit.osmocom.org/11158
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: mncc-python
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I485eb86c69e74693eeae89723de27e376585f1da
Gerrit-Change-Number: 11158
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilira...@gmail.com>

Reply via email to