Commit ac65b253 authored by Michael König's avatar Michael König

fix threading

parent 4a7aadbf
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import time import time
import socket import socket
import threading
from ipaddress import ip_address from ipaddress import ip_address
from collections import deque from collections import deque
...@@ -25,6 +26,7 @@ class SocketInput(InputBase): ...@@ -25,6 +26,7 @@ class SocketInput(InputBase):
self.incomeBuffer = deque() self.incomeBuffer = deque()
self.connectionUp = False self.connectionUp = False
self.socketUp = False self.socketUp = False
self.__stopped = threading.Event()
ip, separator, port = self.options.logServer.rpartition(':') ip, separator, port = self.options.logServer.rpartition(':')
if(':' not in self.options.logServer or port is ''): if(':' not in self.options.logServer or port is ''):
...@@ -43,7 +45,10 @@ class SocketInput(InputBase): ...@@ -43,7 +45,10 @@ class SocketInput(InputBase):
self.createSocket() self.createSocket()
while not self.connectToServer(): while not self.connectToServer():
pass if self.__stopped:
return
else:
pass
def createSocket(self): def createSocket(self):
try: try:
...@@ -63,10 +68,10 @@ class SocketInput(InputBase): ...@@ -63,10 +68,10 @@ class SocketInput(InputBase):
return True return True
except socket.error: except socket.error:
print("Error: Could not connect to " + self.dst + ". Retrying in " + str(LOGSERVER_CONNECT_RETRY_TIME) + "s ...") print("Error: Could not connect to " + self.dst + ". Retrying in " + str(LOGSERVER_CONNECT_RETRY_TIME) + "s ...")
time.sleep(LOGSERVER_CONNECT_RETRY_TIME) self.__stopped.wait(LOGSERVER_CONNECT_RETRY_TIME)
return False return False
else: else:
time.sleep(LOGSERVER_CONNECT_RETRY_TIME) self.__stopped.wait(LOGSERVER_CONNECT_RETRY_TIME)
return False return False
def reconnectToServer(self): def reconnectToServer(self):
...@@ -75,9 +80,13 @@ class SocketInput(InputBase): ...@@ -75,9 +80,13 @@ class SocketInput(InputBase):
self.createSocket() self.createSocket()
while not self.connectToServer(): while not self.connectToServer():
pass if self.__stopped:
return
else:
pass
def tearDown(self): def tearDown(self):
self.__stopped.set()
self.socket.close() self.socket.close()
pass pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment