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

fix threading

parent 4a7aadbf
......@@ -2,6 +2,7 @@
import time
import socket
import threading
from ipaddress import ip_address
from collections import deque
......@@ -25,6 +26,7 @@ class SocketInput(InputBase):
self.incomeBuffer = deque()
self.connectionUp = False
self.socketUp = False
self.__stopped = threading.Event()
ip, separator, port = self.options.logServer.rpartition(':')
if(':' not in self.options.logServer or port is ''):
......@@ -43,7 +45,10 @@ class SocketInput(InputBase):
self.createSocket()
while not self.connectToServer():
pass
if self.__stopped:
return
else:
pass
def createSocket(self):
try:
......@@ -63,10 +68,10 @@ class SocketInput(InputBase):
return True
except socket.error:
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
else:
time.sleep(LOGSERVER_CONNECT_RETRY_TIME)
self.__stopped.wait(LOGSERVER_CONNECT_RETRY_TIME)
return False
def reconnectToServer(self):
......@@ -75,9 +80,13 @@ class SocketInput(InputBase):
self.createSocket()
while not self.connectToServer():
pass
if self.__stopped:
return
else:
pass
def tearDown(self):
self.__stopped.set()
self.socket.close()
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