|
15 | 15 |
|
16 | 16 |
|
17 | 17 | class PickleBasedKernelRegistryLoader(AbstractKernelRegistryLoader[KernelRegistry]): |
18 | | - def __init__(self, last_registry_file_path: Path, legacy_registry_file_path: Path) -> None: |
| 18 | + def __init__( |
| 19 | + self, |
| 20 | + last_registry_file_path: Path, |
| 21 | + fallback_registry_file_path: Path, |
| 22 | + legacy_registry_file_path: Path, |
| 23 | + ) -> None: |
19 | 24 | self._last_registry_file_path = last_registry_file_path |
| 25 | + self._fallback_registry_file_path = fallback_registry_file_path |
20 | 26 | self._legacy_registry_file_path = legacy_registry_file_path |
21 | 27 |
|
22 | 28 | @override |
23 | 29 | async def load_kernel_registry(self) -> KernelRegistry: |
24 | 30 | legacy_registry_file = self._legacy_registry_file_path |
25 | | - last_registry_file = self._last_registry_file_path |
| 31 | + fallback_registry_file = self._fallback_registry_file_path |
| 32 | + final_file_path = self._last_registry_file_path |
| 33 | + if not final_file_path.is_file(): |
| 34 | + log.warning( |
| 35 | + "Registry file with name {} not found. " |
| 36 | + "Falling back to path with local instance id: {}", |
| 37 | + final_file_path, |
| 38 | + fallback_registry_file, |
| 39 | + ) |
| 40 | + final_file_path = fallback_registry_file |
26 | 41 | try: |
27 | 42 | if os.path.isfile(legacy_registry_file): |
28 | | - shutil.move(legacy_registry_file, last_registry_file) |
| 43 | + shutil.move(legacy_registry_file, final_file_path) |
29 | 44 | except Exception as e: |
30 | 45 | log.warning( |
31 | 46 | "Failed to move legacy kernel registry file {} to {} (err: {})", |
32 | 47 | str(legacy_registry_file), |
33 | | - str(last_registry_file), |
| 48 | + str(final_file_path), |
34 | 49 | str(e), |
35 | 50 | ) |
36 | 51 | try: |
37 | | - with open(last_registry_file, "rb") as f: |
| 52 | + with open(final_file_path, "rb") as f: |
38 | 53 | return pickle.load(f) |
39 | 54 | except EOFError as e: |
40 | | - log.warning("Failed to load the last kernel registry: {}", str(last_registry_file)) |
| 55 | + log.warning("Failed to load the last kernel registry: {}", str(final_file_path)) |
41 | 56 | raise KernelRegistryLoadError from e |
42 | 57 | except FileNotFoundError as e: |
43 | 58 | raise KernelRegistryNotFound from e |
0 commit comments