()
| 263 | stop_event = asyncio.Event() |
| 264 | |
| 265 | async def _ticker(): |
| 266 | nonlocal tick_bytes, total_bytes, last_data_time, last_nonzero_sec, peak_bps |
| 267 | sec = 0 |
| 268 | while not stop_event.is_set(): |
| 269 | await asyncio.sleep(1.0) |
| 270 | if t_start is None: continue |
| 271 | sec += 1 |
| 272 | |
| 273 | bps = tick_bytes |
| 274 | tick_bytes = 0 |
| 275 | peak_bps = max(peak_bps, bps) |
| 276 | elapsed = time.monotonic() - t_start |
| 277 | |
| 278 | if bps > 0: |
| 279 | last_data_time = time.monotonic() |
| 280 | last_nonzero_sec = sec |
| 281 | |
| 282 | avg = total_bytes / elapsed if elapsed > 0 else 0 |
| 283 | color = "green" if bps > 0 else "red" |
| 284 | |
| 285 | await display.update(0, |
| 286 | f"[dim]В ПРОЦЕССЕ[/dim] тек [{color}]{_fmt_speed(bps)}[/{color}] " |
| 287 | f"ср. [cyan]{_fmt_speed(avg)}[/cyan] ({_fmt_size(total_bytes):>8} из {MEDIA_SIZE_MB}МБ) ⏱ {sec:>2}с" |
| 288 | ) |
| 289 | |
| 290 | if time.monotonic() - last_data_time >= STALL_TIMEOUT: |
| 291 | stop_event.set() |
| 292 | if sec >= TOTAL_TIMEOUT: |
| 293 | stop_event.set() |
| 294 | |
| 295 | async def _reader(): |
| 296 | nonlocal total_bytes, tick_bytes, t_start |
no test coverage detected