Example threadpool.pyΒΆ

 1from __future__ import print_function
 2import time
 3import gevent
 4from gevent.threadpool import ThreadPool
 5
 6
 7pool = ThreadPool(3)
 8start = time.time()
 9for _ in range(4):
10    pool.spawn(time.sleep, 1)
11gevent.wait()
12delay = time.time() - start
13print('Running "time.sleep(1)" 4 times with 3 threads. Should take about 2 seconds: %.3fs' % delay)

Current source

Next page: Example udp_client.py