Use finally clause for setting back umask

I noticed this while browsing code commits. The affected code was last changed in #10458.

PS. There is no problem here, it's just more pythonic.