def downloadFiles(self, prefix, files, name, version, downloadRootPath: Path): print('{}: total size: {:.2f} MiB'.format( name, sum(f.size for f in files) / 1024 / 1024)) downloadRootPath.mkdir(exist_ok=True) path = downloadRootPath / name bar = progressbar.ProgressBar(max_value=len(files)) async def f(file: File): await self.downloadUrl(prefix, file, path) bar.update(bar.value + 1) bar.start() with async_pool.Pool(10) as pool: pool.map(f, files) bar.finish() with (path / f'{name}.json').open('w') as f: json.dump({ 'version': version, 'files': [f.toDict() for f in files] }, f)
async def main(): for workers in WORKERS_CASES: with self.assertRaises(TestExcept): with async_pool.Pool(workers) as pool: results = await pool.map_async(afunc_except, ARGS_CASES)
async def main(): for workers in WORKERS_CASES: with async_pool.Pool(workers) as pool: results = await pool.map_async(afunc, ARGS_CASES) self.assertEqual(RESULTS_EXPECTED, set(results))
def testWithExcept(self): for workers in WORKERS_CASES: with self.assertRaises(TestExcept): with async_pool.Pool(workers) as pool: results = pool.map(afunc_except, ARGS_CASES)
def testNoExcept(self): for workers in WORKERS_CASES: with async_pool.Pool(workers) as pool: results = pool.map(afunc, ARGS_CASES) self.assertEqual(RESULTS_EXPECTED, set(results))
def testWorkersCheck(self): with self.assertRaises(ValueError): async_pool.Pool(-1)