Getting the time of actual screen refresh

Thanks for you answer. I need two things to precisely synchronize data files from two different computers. First, analyze data already recorded in a “bad way”, and then, improve my code before re-executing my experiments to record better data.

For the first step, I need the time difference between the moment of code execution and actual screen refresh, because I already recorded data that way. In computer 1, a given line of code wrote to file a timestamp with absolute time, and the next line is cv2.waitKey(500) function. Later in time, the screen displays the image, while computer 2 detects the luminance change with a small photodiode (in the corner of the screen). So, in fact, I have to different delays. Delay 1 is the difference between 2 consecutive lines of code (unknown, but estimated in the 1-10 milisecond range). Delay 2 is the difference between the call to waitKey and the physical response of the monitor.
So, the point is that I have the photodiode signal in one computer, while controlled the screen and recorded timestamps with another. Specifically, I need to know when the timestamp of computer 1 matches in time with photodiode signal in computer 2.

I don’t need to display at a specific, constant rate, but I do need to know as precise as possible when the instruction for screen change was given, relative to the real response of the screen.

For step 2 I have no clue despite your advices, because there can always be a delay between a display function and the next frame of the screen.