Skip to content
Snippets Groups Projects
Commit 329e5a66 authored by Taya Snijder's avatar Taya Snijder
Browse files

small fixes

parent 07eab6da
No related branches found
No related tags found
1 merge request!114fixed file writing bug by adding a thread and locks, added the ability to...
...@@ -24,10 +24,7 @@ __all__ = ["statistics_writer"] ...@@ -24,10 +24,7 @@ __all__ = ["statistics_writer"]
class statistics_writer: class statistics_writer:
def __init__(self, new_file_time_interval, file_location, statistics_mode, debug_mode=False): def __init__(self, new_file_time_interval, file_location, statistics_mode):
if debug_mode:
logger.setLevel(logging.DEBUG)
logger.debug("Setting loglevel to DEBUG")
# all variables that deal with the SST matrix that's currently being decoded # all variables that deal with the SST matrix that's currently being decoded
self.current_matrix = None self.current_matrix = None
...@@ -187,3 +184,4 @@ class statistics_writer: ...@@ -187,3 +184,4 @@ class statistics_writer:
self.write_matrix() self.write_matrix()
finally: finally:
self.file.close() self.file.close()
logger.debug(f"{self.file} closed")
...@@ -5,6 +5,9 @@ from statistics_writer import statistics_writer ...@@ -5,6 +5,9 @@ from statistics_writer import statistics_writer
import sys import sys
import signal import signal
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("statistics_writer")
parser = argparse.ArgumentParser(description='Arguments to configure the TCP connection and writer mode') parser = argparse.ArgumentParser(description='Arguments to configure the TCP connection and writer mode')
parser.add_argument('--address', type=str, help='the address to connect to') parser.add_argument('--address', type=str, help='the address to connect to')
...@@ -35,11 +38,15 @@ if __name__ == "__main__": ...@@ -35,11 +38,15 @@ if __name__ == "__main__":
mode = args.mode mode = args.mode
debug = args.debug debug = args.debug
if debug:
logger.setLevel(logging.DEBUG)
logger.debug("Setting loglevel to DEBUG")
# creates the TCP receiver that is given to the writer # creates the TCP receiver that is given to the writer
receiver = tcp_receiver(address, port) receiver = tcp_receiver(address, port)
# create the writer # create the writer
writer = statistics_writer(new_file_time_interval=interval, file_location=location, statistics_mode=mode, debug_mode=debug) writer = statistics_writer(new_file_time_interval=interval, file_location=location, statistics_mode=mode)
# start looping # start looping
try: try:
......
...@@ -39,14 +39,14 @@ while True: ...@@ -39,14 +39,14 @@ while True:
conn, addr = s.accept() conn, addr = s.accept()
with conn: with conn:
logger.debug('Connected by: ', addr) logger.debug(f'Connected by: {addr}')
while True: while True:
time.sleep(INTERVAL) time.sleep(INTERVAL)
conn.sendall(data) conn.sendall(data)
except Exception as e: except Exception as e:
logger.warning(f"Exception occured: {e}" ) logger.warning(f"Exception occurred: {e}")
# just do 2 interrupt within a second to quit the program # just do 2 interrupt within a second to quit the program
time.sleep(1) time.sleep(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment