You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
781 B

import asyncio
from multiprocessing import Process
from concurrent.futures import ProcessPoolExecutor
import util
@util.measure_performance
def async_compute_task():
with ProcessPoolExecutor() as pool:
futures = [pool.submit(util.compute_task) for _ in range(5)]
for future in futures:
future.result()
@util.measure_performance_async
async def async_io_task():
chunk_size = len(util.urls) // 5
chunks = [
util.urls[i:i + chunk_size]
for i in range(0, len(util.urls), chunk_size)
]
for chunk in chunks:
tasks = [util.fetch_url_async(url) for url in chunk]
await asyncio.gather(*tasks)
def main():
async_compute_task()
asyncio.run(async_io_task())
if __name__ == "__main__":
main()