Skip to content

Commit 2b8c6ef

Browse files
authored
fix: avoid RuntimeWarning from run_sync on tzdata install in pyodide (#2574)
1 parent 9046d32 commit 2b8c6ef

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

cognite/client/utils/_pyodide_helpers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
logger = logging.getLogger(__name__)
2121

22+
_TASK_REF_TZDATA: object = None # We need a global ref
23+
2224

2325
def patch_sdk_for_pyodide() -> None:
2426
# -------------------
@@ -65,10 +67,12 @@ def patch_sdk_for_pyodide() -> None:
6567
# internally for e.g. datapoints and workflows.
6668
# Note: This convenience will only work in chromium-based browsers (as of Sept 2025)
6769
try:
70+
import asyncio
71+
6872
import micropip # type: ignore [import-not-found]
69-
from pyodide.ffi import run_sync # type: ignore [import-not-found]
7073

71-
run_sync(micropip.install("tzdata"))
74+
global _TASK_REF_TZDATA # keep the gc at bay
75+
_TASK_REF_TZDATA = asyncio.create_task(micropip.install("tzdata"))
7276
except Exception:
7377
logger.debug(
7478
"Could not load 'tzdata' package automatically in pyodide. You may need to do this manually:"

0 commit comments

Comments
 (0)