Skip to content

Commit 1ace2f7

Browse files
authored
Add retries for shortcut_create. (#358)
Fixes #357
1 parent 9978d47 commit 1ace2f7

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

src/manage/startutils.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _native
2+
import time
23

34
from .fsutils import rmtree, unlink
45
from .logging import LOGGER
@@ -47,15 +48,28 @@ def _make(root, prefix, item, allow_warn=True):
4748
LOGGER.debug("Path: %s", lnk)
4849
LOGGER.debug("Directory: %s", root)
4950
return None
50-
_native.shortcut_create(
51-
lnk,
52-
target,
53-
arguments=_unprefix(item.get("Arguments"), prefix),
54-
working_directory=_unprefix(item.get("WorkingDirectory"), prefix)
55-
or _native.shortcut_default_cwd(),
56-
icon=_unprefix(item.get("Icon"), prefix),
57-
icon_index=item.get("IconIndex", 0),
58-
)
51+
first_exc = None
52+
for retry in range(5):
53+
try:
54+
_native.shortcut_create(
55+
lnk,
56+
target,
57+
arguments=_unprefix(item.get("Arguments"), prefix),
58+
working_directory=_unprefix(item.get("WorkingDirectory"), prefix)
59+
or _native.shortcut_default_cwd(),
60+
icon=_unprefix(item.get("Icon"), prefix),
61+
icon_index=item.get("IconIndex", 0),
62+
)
63+
break
64+
except OSError as ex:
65+
# No errors are reasonably expected here, so we'll retry for any.
66+
# So far, all we've observed have been race conditions.
67+
if not first_exc:
68+
first_exc = ex
69+
time.sleep(0.1)
70+
if first_exc:
71+
LOGGER.debug("Failed to create shortcut")
72+
raise first_exc
5973
return lnk
6074

6175

0 commit comments

Comments
 (0)