def __exit__(self, exc_type, exc_val, exc_tb): os.fchdir(self.orig_fd) os.chroot(".") os.close(self.orig_fd) os.close(self.chroot_fd) self.umount()