コード例 #1
0
ファイル: get_data.py プロジェクト: zjsnr/zjsn_uncensor
    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)
コード例 #2
0
ファイル: test.py プロジェクト: gwy15/async_pool
 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)
コード例 #3
0
ファイル: test.py プロジェクト: gwy15/async_pool
 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))
コード例 #4
0
ファイル: test.py プロジェクト: gwy15/async_pool
 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)
コード例 #5
0
ファイル: test.py プロジェクト: gwy15/async_pool
 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))
コード例 #6
0
ファイル: test.py プロジェクト: gwy15/async_pool
 def testWorkersCheck(self):
     with self.assertRaises(ValueError):
         async_pool.Pool(-1)