Just a random anecdote: I've been badly burned by the heapq for timeouts; although I understand the advantages of the heap in general I think the Python library version is shot-down in practice due to being a purely-Python implementation. I moved to rbtree and suddenly my throughput shot up.