remove acquire() and release() functions and run the threads as deamons for easier cleanups
This commit is contained in:
@@ -40,33 +40,13 @@ class ReceiverThread(Thread):
|
||||
else:
|
||||
return
|
||||
|
||||
def threadId(self):
|
||||
if hasattr(self, '_thread_id'):
|
||||
return self._thread_id
|
||||
for id, thread in _active.items():
|
||||
if thread is self:
|
||||
return id
|
||||
|
||||
def stopThread(self):
|
||||
id = self.threadId()
|
||||
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(id, ctypes.py_object(SystemExit))
|
||||
if 1 < res:
|
||||
ctypes.pythonapi.PyThreadState_SetAsyncExc(id, 0)
|
||||
|
||||
# @brief Receives and sends messages to EuroScope plugins
|
||||
class Euroscope:
|
||||
def __init__(self):
|
||||
def __init__(self, configPath : str, config : Server, aman):
|
||||
self.Context = None
|
||||
self.ReceiverSocket = None
|
||||
self.ReceiverThread = None
|
||||
self.NotificationSocket = None
|
||||
|
||||
def __del__(self):
|
||||
self.release()
|
||||
|
||||
# @brief Initializes the ZMQ socket
|
||||
# @param[in] config The server configuration
|
||||
def acquire(self, configPath : str, config : Server, aman):
|
||||
self.Context = zmq.Context()
|
||||
|
||||
# find the key directories
|
||||
@@ -97,6 +77,7 @@ class Euroscope:
|
||||
self.ReceiverSocket.bind('tcp://' + config.Address + ':' + str(config.PortReceiver))
|
||||
self.ReceiverSocket.setsockopt(zmq.SUBSCRIBE, b'')
|
||||
self.ReceiverThread = ReceiverThread(self.ReceiverSocket, aman)
|
||||
self.ReceiverThread.setDaemon(True)
|
||||
self.ReceiverThread.start()
|
||||
print('Listening to tcp://' + config.Address + ':' + str(config.PortReceiver))
|
||||
|
||||
@@ -108,22 +89,6 @@ class Euroscope:
|
||||
self.NotificationSocket.bind('tcp://' + config.Address + ':' + str(config.PortNotification))
|
||||
print('Publishing to tcp://' + config.Address + ':' + str(config.PortNotification))
|
||||
|
||||
def release(self):
|
||||
if None != self.ReceiverThread:
|
||||
self.ReceiverThread.stopThread()
|
||||
self.ReceiverThread.join()
|
||||
self.ReceiverThread = None
|
||||
|
||||
if None != self.ReceiverSocket:
|
||||
self.ReceiverSocket.close()
|
||||
self.ReceiverSocket = None
|
||||
|
||||
if None != self.NotificationSocket:
|
||||
self.NotificationSocket.close()
|
||||
self.NotificationSocket = None
|
||||
|
||||
self.Context = None
|
||||
|
||||
def sendSequence(self, airport : str, inbounds, weather):
|
||||
if None == self.NotificationSocket:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user