Skip to content

Commit bb374f1

Browse files
committed
FIX: Return to cwd on exception in InTemporaryDirectory
1 parent 323a88a commit bb374f1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

nibabel/tmpdirs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
def _chdir(path):
2121
cwd = os.getcwd()
2222
os.chdir(path)
23-
yield
24-
os.chdir(cwd)
23+
try:
24+
yield
25+
finally:
26+
os.chdir(cwd)
2527

2628

2729
from .deprecated import deprecate_with_version

0 commit comments

Comments
 (0)