PsychoPy does not download Pupil Labs Surface Data


I have been trying to integrate my psychopy experiment with the Pupil Labs Pupil Core eye tracker. However, the PsychoPy Runner becomes unresponsive when I include my eye tracking code. Below is my eye tracking function, embedded in my experimental code. And attached is my entire experimental code.

def is_looking_at_surface(surface_name):
    context = zmq.Context()
    # open a req port to talk to pupil
    addr = ""  # remote ip or localhost
    req_port = "50020"  # same as in the pupil remote gui
    req = context.socket(zmq.REQ)
    req.connect("tcp://{}:{}".format(addr, req_port))
    # ask for the sub port
    sub_port = req.recv_string()

    # open a sub port to listen to pupil
    sub = context.socket(zmq.SUB)
    sub.connect("tcp://{}:{}".format(addr, sub_port))
    sub.setsockopt_string(zmq.SUBSCRIBE, "surface")

    topic = sub.recv_string()
    msg = sub.recv()  # bytes
    surfaces = loads(msg, raw=False)
    filtered_surface = {
        k: v for k, v in surfaces.items() if surfaces["name"] == surface_name
    # note that we may have more than one gaze position data point (this is expected behavior)

    gaze_positions = filtered_surface["gaze_on_surfaces"]

    for gaze_pos in gaze_positions:
        norm_gp_x, norm_gp_y = gaze_pos["norm_pos"]

        # only print normalized gaze positions within the surface bounds
        if 0 <= norm_gp_x <= 1 and 0 <= norm_gp_y <= 1:
            return True
            return False (26.4 KB)