4_100k_threads.py 506 Bytes
#!/usr/bin/env python
import threading
import time

finished_count = 0
finished_count_lock = threading.Lock()

def slow_op(n):
    global finished_count
    time.sleep(1)
    with finished_count_lock:
        finished_count += 1

def main():
    threads = [
            threading.Thread(target=slow_op, args=(i,))
            for i in range(100 * 1000)
            ]
    for t in threads:
        t.start()
    for t in threads:
        t.join()

main()
print("finished_count = {}".format(finished_count))