(uris: Iterable[str], workers=10)
| 38 | |
| 39 | |
| 40 | def prefetch_mirror(uris: Iterable[str], workers=10): |
| 41 | logger.info("Caching AST patterns") |
| 42 | cache.ASTPatternCache.proxy() |
| 43 | |
| 44 | logger.info("Caching list of packages on pypi") |
| 45 | cache.PyPIPackageList.proxy() |
| 46 | |
| 47 | #logger.info("Prefetching package JSON information") |
| 48 | #lm = mirror.LocalMirror() |
| 49 | #pkgs = tuple(lm.list_packages()) |
| 50 | #for x in tqdm.tqdm(pkgs, leave=False): |
| 51 | # lm.get_json(x) |
| 52 | |
| 53 | loop = asyncio.get_event_loop() |
| 54 | |
| 55 | pf = github.GitHubPrefetcher() |
| 56 | loop.create_task(pf.process()) |
| 57 | |
| 58 | uri_queue = AsyncQueue(desc="Mirror package prefetch") |
| 59 | |
| 60 | workers = [loop.create_task(fetch_package(uri_queue, pf)) for _ in range(workers)] |
| 61 | |
| 62 | for uri in uris: |
| 63 | uri_queue.put_nowait(uri) |
| 64 | |
| 65 | logger.info("Waiting for prefetch workers to finish") |
| 66 | |
| 67 | loop.run_until_complete(uri_queue.join()) |
| 68 | |
| 69 | # Cancel prefetch workers |
| 70 | for worker in workers: |
| 71 | worker.cancel() |
| 72 | |
| 73 | # Wait for all tasks to finish |
| 74 | logger.info("All coroutines spawned, waiting for work to finish...") |
| 75 | loop.run_until_complete(pf.queue.put(github.GitHubPrefetcher.STOP)) |
| 76 | |
| 77 | pending = asyncio.all_tasks(loop=loop) |
| 78 | loop.run_until_complete(asyncio.gather(*pending)) |
| 79 | |
| 80 | loop.stop() |
| 81 | loop.close() |
| 82 | |
| 83 | |
| 84 |
nothing calls this directly
no test coverage detected