Skip to content

Instantly share code, notes, and snippets.

View mhihasan's full-sized avatar

Hasanul Islam mhihasan

View GitHub Profile
[tox]
envlist = lint,py3{6,8,9}
skip_missing_interpreters = true
[testenv]
deps =
-r requirements/test.txt
py36: -r requirements/py36.txt
commands =
pytest {posargs:tests}
@mhihasan
mhihasan / dynamodb_parallel_scan.py
Last active July 10, 2023 21:36
Dynamodb Parallel Scanner
import os
import time
import csv
from concurrent.futures import ThreadPoolExecutor, wait
import boto3
dynamo_client = boto3.resource("dynamodb").meta.client
@mhihasan
mhihasan / run_tasks_concurrently.py
Created July 26, 2023 15:42
Run Tasks as a stream in python
async def run_tasks_concurrently(fn, input_params, *, max_concurrency):
input_params_iter = iter(input_params)
# total_tasks = len(input_params)
total_completed_tasks = 0
results = []
tasks = {asyncio.create_task(fn(param)) for param in itertools.islice(input_params_iter, max_concurrency)}
while tasks:
finished, tasks = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)