def read_json(path):
with jsonlines.open(path) as reader:
for inx, obj in enumerate(reader, start=1):
yield obj
async def main(path, engine):
N = 100
tasks = asyncio.Queue()
for item in read_json(path=path):
tasks.put_nowait(load_today_db(engine=engine, obj=item))
async def worker():
while not tasks.empty():
await tasks.get_nowait()
await asyncio.gather(*[worker() for _ in range(N)])