OpenCV update breaks waitKey behaviour

I took back a python project that uses openCV to show images in a separate window. The project is in python 3.8 and I am upgrading it to python 3.12. I also updating openCV from version 4.4.0.46 to version 4.11.0.86.
The project consist of a local web server with Flask that can do various operations depending on the API call.

One API call result in the following set of lines of code:

   window_name = "projector"
   if cv2.getWindowProperty(window_name, 0) >= 0:
            cv2.imshow(window_name, full_screen_frame)
   else:
            cv2.namedWindow(window_name, cv2.WND_PROP_FULLSCREEN)
            cv2.moveWindow(window_name, window_move[0], window_move[1])
            cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

            cv2.imshow(window_name, full_screen_frame)
            cv2.waitKey()

In the 4.4 version, I can call this API multiple times and everything works fine.
In the 4.11 version I have an exception on the getWindowProperty call. I fixed it using a try/except clause and the image shows just fine. But when the API il called again, the code stop executing a the getWindowProperty line, as if the waitKey is blocking the execution.

I have another API that closes the window with cv2.destroyAllWindows() but it also frezze on that line with the version 4.11

I don’t understand this change of behaviour. Do you know how to solve this issue ?
Thank you

flask is for making web servers/services.

you cannot mix that with desktop GUI.

the lifecycles don’t mesh. each has its own lifecycle/event loop. you’d have to know not just how each does its event looping, but you’d also have to know if any of those involves threading, and if the other would tolerate such threading.

if any GUI provided by OpenCV used to work in a flask loop, then that worked outside of spec.

you could try to use a proper GUI toolkit, from within your flask lifecycle, e.g. Tkinter, Qt, GTK, WX, OpenGL/imgui, …