mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-18 06:30:23 -04:00
add more concurrent examples
This commit is contained in:
parent
6c65e7d226
commit
f35541a061
3 changed files with 104 additions and 0 deletions
23
Concurrence_examples/getenv_example.py
Normal file
23
Concurrence_examples/getenv_example.py
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue