|
4 | 4 | import atexit
|
5 | 5 | import logging
|
6 | 6 | import os
|
7 |
| -import sys |
8 | 7 | import threading
|
9 | 8 | from concurrent.futures import ThreadPoolExecutor, wait
|
10 | 9 | from typing import TYPE_CHECKING, Any, TypeVar
|
@@ -38,45 +37,6 @@ class SyncError(Exception):
|
38 | 37 | pass
|
39 | 38 |
|
40 | 39 |
|
41 |
| -# TODO: not sure if there is a better place to put this function, so I've kept it here for now. |
42 |
| -def _make_shutdown_asyncgens_noop_for_pyodide() -> None: |
43 |
| - """ |
44 |
| - Patch Pyodide's WebLoop to fix interoperability with pytest-asyncio. |
45 |
| -
|
46 |
| - WebLoop.shutdown_asyncgens() raises NotImplementedError, which causes |
47 |
| - pytest-asyncio to issue warnings during test cleanup and potentially |
48 |
| - cause resource leaks that make tests hang. This is a bit of a |
49 |
| - hack, but it allows us to run tests that use pytest-asyncio. |
50 |
| -
|
51 |
| - This is necessary because pytest-asyncio tries to clean up async generators |
52 |
| - when tearing down test event loops, but Pyodide's WebLoop doesn't support |
53 |
| - this as it integrates with the browser's event loop rather than managing |
54 |
| - its own lifecycle. |
55 |
| - """ |
56 |
| - try: |
57 |
| - if not IS_WASM and "pyodide" not in sys.modules: |
58 |
| - return |
59 |
| - |
60 |
| - import pyodide.webloop |
61 |
| - |
62 |
| - if hasattr(pyodide.webloop.WebLoop, "shutdown_asyncgens"): |
63 |
| - |
64 |
| - async def no_op_shutdown_asyncgens(self) -> None: # type: ignore[no-untyped-def] # noqa: ANN001 |
65 |
| - return |
66 |
| - |
67 |
| - pyodide.webloop.WebLoop.shutdown_asyncgens = no_op_shutdown_asyncgens |
68 |
| - logger.debug("Patched WebLoop.shutdown_asyncgens for pytest-asyncio compatibility") |
69 |
| - |
70 |
| - # If patching fails for any reason, we log it, but we won't want to crash Zarr |
71 |
| - except Exception as e: |
72 |
| - msg = f"Could not patch WebLoop for pytest compatibility: {e}" |
73 |
| - logger.debug(msg) |
74 |
| - |
75 |
| - |
76 |
| -if IS_WASM: |
77 |
| - _make_shutdown_asyncgens_noop_for_pyodide() |
78 |
| - |
79 |
| - |
80 | 40 | def _get_lock() -> threading.Lock:
|
81 | 41 | """Allocate or return a threading lock.
|
82 | 42 |
|
|
0 commit comments