`dl_open_guard` should restore flag even after exception (#96231)
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