add more concurrent examples

This commit is contained in:
Mia von Steinkirch 2020-03-03 15:36:03 -08:00
parent 6c65e7d226
commit f35541a061
3 changed files with 104 additions and 0 deletions

View file

@ -0,0 +1,23 @@
import time
from gevent.pool import Pool
from gevent import monkey
# Note that you can spawn many workers with gevent since the cost of creating and switching is very low
NUM_WORKERS = 4
# Monkey-Patch socket module for HTTP requests
monkey.patch_socket()
start_time = time.time()
pool = Pool(NUM_WORKERS)
for address in WEBSITE_LIST:
pool.spawn(check_website, address)
# Wait for stuff to finish
pool.join()
end_time = time.time()
print("Time for GreenSquirrel: %ssecs" % (end_time - start_time))
g