Can anyone advise on how to stop this happening.

The external monitor attached to it goes black for a few seconds but then comes back to show the Desktop etc.

When I boot into Windows 7 64 bit Pro (via Boot Camp) this never happens. So I don't think it's a hardware issue.

Please advise.

**Update**

Removed OS version from title as issue occurred in several versions. Added versions where seen as tags.

It never happened with Mavericks (but did following the upgrade to Yosemite, went away, then came back after a while after upgrading to El Capitan (I think) but also Sierra).