Wait until no threads are still running tasks. This is intended to be used when testing code with trio.to_thread to make sure no tasks are still making progress in a thread. See the following code for a usage example:: async def wait_all_settled(): while True:
()
| 85 | |
| 86 | |
| 87 | async def wait_all_threads_completed() -> None: |
| 88 | """Wait until no threads are still running tasks. |
| 89 | |
| 90 | This is intended to be used when testing code with trio.to_thread to |
| 91 | make sure no tasks are still making progress in a thread. See the |
| 92 | following code for a usage example:: |
| 93 | |
| 94 | async def wait_all_settled(): |
| 95 | while True: |
| 96 | await trio.testing.wait_all_threads_complete() |
| 97 | await trio.testing.wait_all_tasks_blocked() |
| 98 | if trio.testing.active_thread_count() == 0: |
| 99 | break |
| 100 | """ |
| 101 | |
| 102 | await checkpoint() |
| 103 | |
| 104 | try: |
| 105 | active_threads_local = _active_threads_local.get() |
| 106 | except LookupError: |
| 107 | # If there would have been active threads, the |
| 108 | # _active_threads_local would have been set |
| 109 | return |
| 110 | |
| 111 | while active_threads_local.count != 0: |
| 112 | await active_threads_local.event.wait() |
| 113 | |
| 114 | |
| 115 | def active_thread_count() -> int: |
searching dependent graphs…