File: threadpool.py

package info (click to toggle)
python-gevent 1.1.1-2~bpo8%2B1
  • links: PTS
  • area: main
  • in suites: jessie-backports
  • size: 12,472 kB
  • sloc: python: 73,749; ansic: 26,302; sh: 11,090; makefile: 927; awk: 18
file content (13 lines) | stat: -rw-r--r-- 339 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
from __future__ import print_function
import time
import gevent
from gevent.threadpool import ThreadPool


pool = ThreadPool(3)
start = time.time()
for _ in range(4):
    pool.spawn(time.sleep, 1)
gevent.wait()
delay = time.time() - start
print('Running "time.sleep(1)" 4 times with 3 threads. Should take about 2 seconds: %.3fs' % delay)