def update_progress(): print('updating progress...') for idx, conn in children.items(): if conn: send_msg(conn, b'ready') data = pickle.loads(recv_msg(conn)) print(data) progress[idx].update(data) print('progress updated!')
def get_progress_thread(conn, idx): print('thread created') send_msg(conn, b'ready') while conn: recv_msg(conn) print('sending data') update_progress() send_msg(conn, pickle.dumps(progress)) print('closing connection') conn.close()
def test_unsplit_messaging(): """ Test if the message sending and receiving work as expected. Test for unsplit messages. (msg < BUFFER_SIZE) """ msg = ('test-msg', 'test-data') send_msg(msg[0], msg[1], ('127.0.0.1', 6667)) received = RECEIVER.receive_msg() assert unpack_msg(received[0]) == (msg[0], msg[1])
def client_thread(conn, idx): print('thread created') progress = {} all_progress[idx] = progress while conn: data = conn.recv(1024) if not data: break data = pickle.loads(data) progress.update(data) print(all_progress) send_msg(conn, b'good') sleep(.1) print('closing connection') conn.close()
def test_split_messaging_2(): """ Test if the message sending and receiving work as expected. Test for split (2-parts) messages. (msg > BUFFER_SIZE) """ msg = ('test-msg', b'1' * (SERVER.buffersize + 10)) send_msg(msg[0], msg[1], ('127.0.0.1', 6667)) received = RECEIVER.receive_msg() assert received is None received = RECEIVER.receive_msg() # Check content assert unpack_msg(received[0]) == (msg[0], msg[1])