The same advice holds for proving theorems. When trying to prove a difficult result, particularly a well-studied open question, it often seems some evil deity finds ways to foil your many proof attempts just as they almost seem to work. Don't give up. Remain optimistic that you can prove this theorem and keep the patience trying new approaches even as each approach gets cruelly shot down. Only when you've exhausted all of your ideas should you move on to the next result.
Over the years I have kept my optimism about proving a result, but I haven't had as much patience as earlier in my research career. Partly because as one gets older one gets more non-research responsibilities both at the university and in the community, though this is more an excuse than a reason. I also find it more difficult these days to focus on a single problem for hours or days at a time.
Let this be a lesson to young researchers. Don't worry that the older famous researchers have not solved the big open questions; most (but not all) do not have as much patience to focus on a problem and explore as many of the possible proof techniques as well as you can.