Skip to content

Commit 6fc280e

Browse files
committed
feat: prevent more event loop blocking
1 parent 7c63463 commit 6fc280e

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

findmy/reports/anisette.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,6 @@ def __init__(
296296
if isinstance(libs_path, str):
297297
libs_path = Path(libs_path)
298298

299-
if libs_path is None or not libs_path.is_file():
300-
logger.info(
301-
"The Anisette engine will download libraries required for operation, "
302-
"this may take a few seconds...",
303-
)
304-
if libs_path is None:
305-
logger.info(
306-
"To speed up future local Anisette initializations, "
307-
"provide a filesystem path to load the libraries from.",
308-
)
309-
310299
# we do not yet initialize Anisette in order to prevent blocking the event loop,
311300
# since the anisette library will download the required libraries synchronously.
312301
self._ani: Anisette | None = None
@@ -323,6 +312,17 @@ async def _get_ani(self) -> Anisette:
323312
if self._ani is not None:
324313
return self._ani
325314

315+
if self._libs_path is None or not self._libs_path.is_file():
316+
logger.info(
317+
"The Anisette engine will download libraries required for operation, "
318+
"this may take a few seconds...",
319+
)
320+
if self._libs_path is None:
321+
logger.info(
322+
"To speed up future local Anisette initializations, "
323+
"provide a filesystem path to load the libraries from.",
324+
)
325+
326326
files: list[BinaryIO | Path] = []
327327
if self._state_blob is not None:
328328
files.append(self._state_blob)
@@ -331,16 +331,20 @@ async def _get_ani(self) -> Anisette:
331331

332332
loop = asyncio.get_running_loop()
333333
ani = await loop.run_in_executor(None, Anisette.load, *files)
334+
is_provisioned = await loop.run_in_executor(None, lambda: ani.is_provisioned)
334335

335336
if self._libs_path is not None:
336337
ani.save_libs(self._libs_path)
337338

338-
if not self._is_new_session and not ani.is_provisioned:
339+
if not self._is_new_session and not is_provisioned:
339340
logger.warning(
340341
"The Anisette state that was loaded has not yet been provisioned. "
341342
"Was the previous session saved properly?",
342343
)
343344

345+
# pre-provision to ensure that the VM has initialized
346+
await loop.run_in_executor(None, ani.provision)
347+
344348
self._ani = ani
345349
return ani
346350

0 commit comments

Comments
 (0)