async def get_message(): future = asyncio.Future() order = order_sock.recv_string() future.set_result(order) asyncio.wait(0.1) if future.done(): print(future.result()) return future async def send_frame(): grabbed, frame = camera.read() frame = cv2.resize(frame, (640, 480)) encoded, buffer = cv2.imencode('.jpg', frame) jpg_as_text = base64.b64encode(buffer) frame_sock.send(jpg_as_text) await asyncio.sleep(0.01) async def stream(): while True: await asyncio.gather( get_message() ,send_frame() )