iMac display goes to sleep randomly during use -- how and why? Are there event logs? Over the past month or two the display on my old iMac 27-inch ("late 2009", running High Sierra 10.13.6) would randomly and suddenly go to sleep (sudden dead black) while in use (while typing, mousing, scrolling, etc.), but only about once a week or even less.

The first time I thought it had crashed (having the display go dead black while typing is very disconcerting) and I power-cycled it.  The second time I realized the system was still running, and I logged in remotely with SSH to find everything "normal".  I finally realized I could simply wake the display again with Control-Shift-Eject and then wiggling the cursor or hitting another key.

These past few days it started doing this very frequently -- every few minutes, or even more often for periods.

At first I thought it might be a software bug as it seemed to only happen when using the browser (perhaps a GPU bug).

Then, because it seemed OK for a short while after being idle for an hour or more, I thought it might be something to do with overheating, and I played with fan speeds (to the great annoyance of my ears).  At first this seemed to make some difference, but I never really could make any strong correlation.

But then I realized it was probably being put to sleep under software control as apps were fully refreshing their windows upon waking the display (just as they do when returning from the screen saver, for example).

Finally I tried changing the Energy Saver settings to "Never" let the display go to sleep.  This seems to have worked!

Now I've also quieted the fans, and so far (an hour or two of constant use) I have not had the screen suddenly go black since.

Does anyone have any deep understanding of how exactly the system controls display sleep, and whether or not there's any way to see logging of the events controlling display sleep?
You may have a Hot Corner checked. if your mouse touched a hot corner it will respond in a chosen way. One Hot Corner action is to put display to sleep. To check this go to System Preferences, Desktop &amp; Screen Saver. Click on the Screen Saver tab and at the bottom of that pane is a button for Hot Corners. Click this and see if you hve a hot corner set up.