| 143 | return out |
| 144 | |
| 145 | async def run_phase(phase_name: str, concurrency: int, total: int, |
| 146 | timeout: float, jitter: float, results: List[Result]): |
| 147 | sem = asyncio.Semaphore(concurrency) |
| 148 | started = 0 |
| 149 | |
| 150 | async def worker(idx: int): |
| 151 | nonlocal started |
| 152 | async with sem: |
| 153 | if jitter > 0: |
| 154 | await asyncio.sleep(random.random()*jitter) |
| 155 | res = await socks5_http_get(timeout, phase_name) |
| 156 | results.append(res) |
| 157 | |
| 158 | tasks = [] |
| 159 | for i in range(total): |
| 160 | started += 1 |
| 161 | tasks.append(asyncio.create_task(worker(i))) |
| 162 | await asyncio.gather(*tasks) |
| 163 | |
| 164 | def summarize(results: List[Result]): |
| 165 | ok = [r for r in results if r.ok] |