Run an async function synchronously, handling nested event loops.
(coro)
| 46 | |
| 47 | |
| 48 | def _run_async(coro): |
| 49 | """Run an async function synchronously, handling nested event loops.""" |
| 50 | try: |
| 51 | loop = asyncio.get_running_loop() |
| 52 | except RuntimeError: |
| 53 | loop = None |
| 54 | |
| 55 | if loop is not None and loop.is_running(): |
| 56 | # Already in an async context — create a new thread |
| 57 | import concurrent.futures |
| 58 | with concurrent.futures.ThreadPoolExecutor(max_workers=1) as pool: |
| 59 | future = pool.submit(asyncio.run, coro) |
| 60 | return future.result(timeout=10) |
| 61 | else: |
| 62 | return asyncio.run(coro) |
| 63 | |
| 64 | |
| 65 | def _build_workspace_section(root: Path, current: Path) -> str: |
no test coverage detected