I keep work and my personal life very much separate. Not just when I'm having a hard time in my personal life but also when it's going good. This lets work almost be a sanctuary. When I'm there nothing matter but getting the job done.
It's not easy, but if you are able to develop that separation you can almost shut off your personal problems at will.