This is my first attempt with threading and I have run into numerous hurdles already! So my code runs two threads in parallel, one which runs a function to receive data blocks from the server and puts them into a queue and the other which runs a function that removes the data blocks from the queue and performs calculations until the queue is empty.
The client code is:
import socket
import turtle
import queue
import threading
#import timeit
from tkinter import *
class GUI:
entries = []
def __init__(self, master):
self.master = master
master.title("Collision Detection")
self.buff_data = queue.Queue()
self.t1 = threading.Thread(target = self.recvData)
self.t2 = threading.Thread(target=self.calculate_threshold)
self.entries = []
self.host = '127.0.0.1'
self.port = 5001
self.s = socket.socket()
self.s.connect((self.host, self.port))
self.create_GUI()
def create_GUI(self):
self.input_label = Label(root, text = "Input all the gratings set straight wavelength values in nm")
self.input_label.grid(row = 0)
self.core_string = "Core "
#entries = []
self.label_col_inc = 0
self.entry_col_inc = 1
self.core_range = range(1, 5)
for y in self.core_range:
self.core_text = self.core_string + str(y) + '_' + '25'
self.core_label = Label(root, text = self.core_text)
self.entry = Entry(root)
self.core_label.grid(row=1, column=self.label_col_inc, sticky=E)
self.entry.grid(row=1, column=self.entry_col_inc)
self.entries.append(self.entry)
self.label_col_inc += 2
self.entry_col_inc += 2
self.threshold_label = Label(root, text = "Threshold in nm")
self.entry_threshold = Entry(root)
self.threshold_label.grid(row = 2, sticky = E)
self.entry_threshold.grid(row = 2, column = 1)
self.light_label = Label(root, text = 'Status')
self.light_label.grid(row = 3, column = 3)
self.canvas = Canvas(root, width = 150, height = 50)
self.canvas.grid(row = 4, column = 3)
# Green light
self.green_light = turtle.RawTurtle(self.canvas)
self.green_light.shape('circle')
self.green_light.color('grey')
self.green_light.penup()
self.green_light.goto(0,0)
# Red light
self.red_light = turtle.RawTurtle(self.canvas)
self.red_light.shape('circle')
self.red_light.color('grey')
self.red_light.penup()
self.red_light.goto(40,0)
self.data_button = Button(root, text = "Get data above threshold", command = self.getData)
self.data_button.grid(row = 5, column = 0)
# function to receive TCP data blocks
def getData(self):
#start = timeit.default_timer()
len_message = self.s.recv(4)
print('len_message', len_message)
bytes_length = int(len_message.decode('utf-8')) # for the self-made server
recvd_data = self.s.recv(bytes_length)
print('data', recvd_data)
self.buff_data.put(recvd_data)
#stop = timeit.default_timer()
#print('Time: ', stop - start) gives 0.0002s
self.t1.start()
self.t2.start()
def recvData(self):
len_message = self.s.recv(4)
print('len_message', len_message)
while len_message:
bytes_length = int(len_message.decode('utf-8')) # for the self-made server
recvd_data = self.s.recv(bytes_length)
print('data', recvd_data)
self.buff_data.put(recvd_data)
len_message = self.s.recv(4)
print('len_message', len_message)
else:
print('out of loop')
self.s.close()
def calculate_threshold(self):
#start = timeit.default_timer()
print('Calculating:')
while not self.buff_data.empty():
print('okay enter')
rmv_data = self.buff_data.get()
stringdata = rmv_data.decode('utf-8')
rep_str = stringdata.replace(",", ".")
splitstr = rep_str.split()
inc = 34
wav_threshold = []
for y in self.entries:
straight_wav = float(y.get())
wav = float(splitstr[inc])
wav_diff = wav - straight_wav
if wav_diff < 0:
wav_diff = wav_diff * (-1)
wav_threshold.append(wav_diff)
inc += 56
threshold = float(self.entry_threshold.get())
for x in wav_threshold:
if (x > threshold):
self.red_light.color('red')
self.green_light.color('grey')
else:
self.red_light.color('grey')
self.green_light.color('green')
#stop = timeit.default_timer()
#print('Time: ', stop - start) gives 0.11s
# function to write into the file
def write_file(self,data):
with open("Output.txt", "a") as text_file:
text_file.write('\t'.join(data[0:]))
text_file.write('\n')
if __name__ == '__main__':
root = Tk()
gui = GUI(root)
root.mainloop()
I ran a server code to send only one data block with both threads commented and ran the start and stop variables of getData() and saw it takes 0.0002s to transfer one data block. Then I ran the server code to send only one data block and ran the start and stop variables of only calculate_threshold() and saw it takes 0.12407s to perform the calculations.
Based on this I removed the timeit variables and sent around 34 data blocks (due to limitation of word limit in the body of my post, I have shown only few below) with a time delay of 0.5s after sending 10 data blocks and noticed that I get this in my console:
C:\Users\PycharmProjects\GUI\venv\Scripts\python.exe C:/Users/PycharmProjects/GUI/GUI_v4.py
len_message b'1685'
data b' 2020/03/02\t14:42:05\t318301\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/03\t14:42:05\t318302\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/04\t14:42:05\t318303\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'Calculating:
okay enterlen_message b'1685'
data b' 2020/03/05\t14:42:05\t318411\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/06\t14:42:05\t318411\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/07\t14:42:05\t318411\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/08\t14:42:05\t318411\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/09\t14:42:05\t318411\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/10\t14:42:05\t318411\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/11\t14:42:05\t318411\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b'1685'
data b' 2020/03/12\t14:42:05\t318411\t4\t1\t25\t0\t0\t0\t0\t1513,094\t1516,156\t1519,154\t1521,969\t1525,029\t1527,813\t1530,921\t1533,869\t1536,740\t1539,943\t1542,921\t1545,879\t1548,843\t1551,849\t1554,760\t1557,943\t1560,782\t1563,931\t1566,786\t1569,751\t1572,690\t1575,535\t1578,638\t1581,755\t1584,759\t41\t39\t33\t39\t48\t44\t49\t55\t61\t58\t64\t55\t68\t74\t68\t59\t57\t74\t61\t68\t58\t64\t54\t47\t46\t2\t25\t0\t0\t0\t0\t1512,963\t1515,935\t1518,857\t1521,849\t1524,655\t1527,577\t1530,332\t1533,233\t1536,204\t1539,488\t1542,571\t1545,725\t1549,200\t1552,430\t1555,332\t1558,484\t1561,201\t1564,285\t1567,001\t1569,870\t1572,758\t1575,491\t1578,512\t1581,547\t1584,405\t48\t43\t37\t42\t57\t54\t59\t62\t67\t58\t71\t59\t77\t82\t82\t64\t71\t88\t77\t79\t72\t73\t63\t49\t50\t3\t25\t0\t0\t0\t0\t1513,394\t1516,517\t1519,536\t1522,082\t1525,428\t1527,963\t1531,288\t1534,102\t1536,659\t1539,757\t1542,707\t1545,627\t1548,389\t1551,459\t1554,406\t1557,986\t1560,667\t1564,103\t1567,036\t1570,144\t1573,189\t1575,888\t1579,185\t1582,323\t1585,338\t35\t36\t32\t37\t57\t58\t61\t64\t75\t73\t70\t62\t61\t62\t59\t51\t52\t64\t58\t62\t70\t70\t64\t54\t55\t4\t25\t0\t0\t0\t0\t1512,658\t1515,752\t1518,797\t1521,707\t1524,744\t1527,627\t1530,871\t1534,002\t1537,086\t1540,320\t1543,217\t1546,010\t1548,660\t1551,385\t1554,253\t1557,074\t1560,193\t1563,116\t1566,043\t1568,963\t1571,855\t1574,957\t1577,954\t1581,128\t1584,273\t43\t42\t39\t40\t56\t50\t56\t62\t65\t54\t59\t62\t75\t79\t73\t63\t67\t77\t73\t75\t68\t62\t54\t51\t51\t100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN'
len_message b''
out of loop
okay enter *x 32 times*
Why is there a gap after 3 data blocks printed on the console? Why is the 'Calculating' print statement not printed and why is it first executing the first thread (receiving all data blocks) and then performing the calculations of the second thread?
I wanted both to happen simultaneously. I understand that the second thread takes more time but that is why I added the delay in sending the data to make sure by the time 10 data blocks each of 0.0002s are sent + 0.5s delay is added = 0.502s, by then the loop of the second thread should have executed 5 times.
How can I make sure that they are in parallel? Considering my server is going to be a hardware which will continuously send data blocks at a sampling rate of 100Hz and there will be no limit to the data blocks sent.
Threads run almost simultaneously. with threads, as soon as one starts the next thread starts. therefore there is a slight delay from the 1st to the 2nd.. etc if you're after real simultaneous processing you need to use your cores instead.