Run an asynchronous coroutine in a non-async environment. Args: coroutine: The coroutine to run. Returns: The result of the coroutine.
(coroutine)
| 23 | |
| 24 | |
| 25 | def run_async(coroutine): |
| 26 | """ |
| 27 | Run an asynchronous coroutine in a non-async environment. |
| 28 | |
| 29 | Args: |
| 30 | coroutine: The coroutine to run. |
| 31 | |
| 32 | Returns: |
| 33 | The result of the coroutine. |
| 34 | """ |
| 35 | try: |
| 36 | loop = asyncio.get_event_loop() |
| 37 | except RuntimeError: |
| 38 | loop = asyncio.new_event_loop() |
| 39 | asyncio.set_event_loop(loop) |
| 40 | job = loop.run_until_complete(coroutine) |
| 41 | return job |
| 42 | |
| 43 | |
| 44 | def calc_image_tokens(images: list[str]): |
no outgoing calls
no test coverage detected