`dl_open_guard` should restore flag even after exception (#96231) (#96457)
I.e. follow pattern outlined in https://docs.python.org/3.8/library/contextlib.html#contextlib.contextmanager
Also, return early on non-unix platforms (when `sys.getdlopenflags` is not defined)
Fixes https://github.com/pytorch/pytorch/issues/96159
Pull Request resolved: https://github.com/pytorch/pytorch/pull/96231
Approved by: https://github.com/atalman
(cherry picked from commit 941ff109d32d51d6e93a2c2f4a028ff3826ece31)