'Problem using a queue name in a class function in another thread

My programme reads a thermal camera, put an image on the screen and loops forever. In a separate thread, I have a class function that runs when a button is pressed. The function moves to the next color map in a list each time it's called by a button click. I want to put the resultant color map name in the queue for the main programme to use for the display. This should go to the next color map each time the button is clicked. If I comment out the queue.put, I see the name of the colour map printed on the console and the main programme runs in a loop, updating the display continuously. As soon as the queue.put is uncommented, the main loop does not run.

The procedure in the thread is:

class Index: ind=0

def CMAP(self,queue):                       # Roll round colour maps on button press

    global Colour_map
    global cmap_index
    global cmap_list
    global Cmap_queue
    
    cmap_index+=1                           # increment index
    if cmap_index==len(cmap_list):          # if at max
        cmap_index=0                        # reset to start
    Colour_map=cmap_list[cmap_index]        # look up colour map to use
    #queue.put(Colour_map)                  # and put in queue
    print(Colour_map, Cmap_queue)

When I run the programme, the Colour_map reports the correct name, rolling through the list as it should. The queue name reports as " <queue.Queue object at 0x73523f90 ".

The queue is created in the main programme so:

Cmap_queue=queue.Queue(maxsize=10)

and called thus:

Colour_map=Cmap_queue.get()

I had a test version where the function to update the colormap looped continuously,incrementing the index each pass, then queued it. This worked perfectly. I must be missing something, what am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source