Ejemplo n.º 1
0
def handle_return_connection(connection, client_address, return_queue,
                             return_lock):
    """
    For each client, there is a thread that continously checks for the confirmation that a plot from this client has been rendered.
    This thread takes hold of the return queue, dequeues max 10 objects and checks if there is a return message for the client that is goverend by this thread.
    All other return messages are put back into the queue. Then the lock on the queue is released so that other threads might serve their clients their respecitve messages.
    The return messges belonging to this client are then sent back.
    :param connection:
    :param client_address:
    :param return_queue:
    :param return_lock:
    :return:
    """
    while True:
        return_lock.acquire()
        return_objects = _queue_get_all_no_wait(return_queue, 10)
        if len(return_objects) > 0:
            # print("Received {} return objects".format(len(return_objects)))
            owned_items = []
            for client, plot_id in return_objects:
                if client == client_address:
                    owned_items.append(plot_id)
                else:
                    return_queue.put((client, plot_id))
            return_lock.release()
            for plot_id in owned_items:
                message = plot_id
                send_size(sock=connection, data=message)
        else:
            return_lock.release()
            # print("no return value to send :)")
            time.sleep(0.01)
Ejemplo n.º 2
0
def handle_return_connection(connection, client_address, return_queue, return_lock):
    """
    For each client, there is a thread that continously checks for the confirmation that a plot from this client has been rendered.
    This thread takes hold of the return queue, dequeues max 10 objects and checks if there is a return message for the client that is goverend by this thread.
    All other return messages are put back into the queue. Then the lock on the queue is released so that other threads might serve their clients their respecitve messages.
    The return messges belonging to this client are then sent back.
    :param connection:
    :param client_address:
    :param return_queue:
    :param return_lock:
    :return:
    """
    while True:
        return_lock.acquire()
        if not return_queue: break
        try:
            return_objects = _queue_get_all_no_wait(return_queue, 10)
        except Exception:
            break

        if len(return_objects) > 0:
            owned_items = []
            for client, plot_id in return_objects:
                if client == client_address:
                    owned_items.append(plot_id)
                else:
                    return_queue.put((client,plot_id))
            return_lock.release()
            for plot_id in owned_items:
                message = plot_id
                send_size(sock=connection, data=message)
        else:
            return_lock.release()
            time.sleep(0.01)
Ejemplo n.º 3
0
def push_to_server(queue, sock):
    while True:
        try:
            message = queue.get_nowait()
            send_size(sock, message)
        except Queue.Empty:
            time.sleep(0.01)
    sock.close()
Ejemplo n.º 4
0
def push_to_server(queue, sock):
    while True:
        try:
            message = queue.get_nowait()
            send_size(sock, message)
        except Queue.Empty:
            time.sleep(0.01)
    sock.close()