Fixing rare occation where partitions dissapear just before .format().

This commit is contained in:
Anton Hvornum 2021-03-29 09:09:25 +02:00
parent a156f224a8
commit 3161cd8aff
No known key found for this signature in database
GPG Key ID: F1234C5BA67C59DF
1 changed files with 5 additions and 0 deletions

View File

@ -270,6 +270,11 @@ class Partition():
if allow_formatting is None:
allow_formatting = self.allow_formatting
# To avoid "unable to open /dev/x: No such file or directory"
start_wait = time.time()
while pathlib.Path(path).exists() is False and time.time() - start_wait < 10:
time.sleep(0.025)
if not allow_formatting:
raise PermissionError(f"{self} is not formatable either because instance is locked ({self.allow_formatting}) or a blocking flag was given ({allow_formatting})")