Skip to content

Instantly share code, notes, and snippets.

@alexeygrigorev
alexeygrigorev / tqdm_pool.py
Created December 6, 2018 15:36
Track progress of ProcessPoolExecutor with tqdm
from glob import glob
import multiprocessing
from concurrent.futures import ProcessPoolExecutor
import cv2
from PIL import Image
import imagehash
from tqdm import tqdm
@cgarciae
cgarciae / client-task-pool.py
Last active May 14, 2022 23:00
client-task-pool.py
# client-task-pool.py
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
from pypeln.task import TaskPool
limit = 1000
@cgarciae
cgarciae / client-async-sem.py
Last active May 9, 2022 00:28
client-async-sem.py
# client-async-sem.py
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
limit = 1000
async def fetch(url, session):
async with session.get(url) as response:
@cgarciae
cgarciae / timed.sh
Last active May 9, 2022 00:27
timed.sh
# timed.sh
ulimit -n 3000 # increase to avoid "out of file descriptors" error
python server.py &
sleep 1 # Wait for server to start
/usr/bin/time --format "Memory usage: %MKB\tTime: %e seconds\tCPU usage: %P" "$@"
@bradmontgomery
bradmontgomery / main.py
Created August 21, 2018 02:38
Examples of using concurrent.futures with Threads & Processes and the joblib library to read data from a bunch of files & do some simple parallell processing.
#!/usr/bin/env python
"""
process some data
"""
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
from joblib import Parallel, delayed
import os
import statistics
@reywood
reywood / how-to.md
Last active April 15, 2025 16:37
How to get a stack trace from a stuck/hanging python script

How to get a stack trace for each thread in a running python script

Sometimes a python script will simply hang forever with no indication of where things went wrong. Perhaps it's polling a service that will never return a value that allows the program to move forward. Here's a way to see where the program is currently stuck.

Install gdb and pyrasite

Install gdb.

# Redhat, CentOS, etc