-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParallellTest.py
More file actions
50 lines (42 loc) · 1.2 KB
/
ParallellTest.py
File metadata and controls
50 lines (42 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests
from multiprocessing.dummy import Pool as ThreadPool
from multiprocessing import Pool
import time
urls = [
'http://www.python.org',
'http://www.python.org/about/',
'http://www.onlamp.com/pub/a/python/2003/04/17/metaclasses.html',
'http://www.python.org/doc/',
'http://www.python.org/download/',
'http://www.python.org/getit/',
'http://www.python.org/community/',
'https://wiki.python.org/moin/',
'http://planet.python.org/',
'https://wiki.python.org/moin/LocalUserGroups',
'http://www.python.org/psf/',
'http://docs.python.org/devguide/',
'http://www.python.org/community/awards/'
# etc..
]
t0 = time.time()
#responses = []
#for url in urls:
# responses.append(requests.get(url))
## Make the Pool of workers
#pool = ThreadPool(12)
## Open the urls in their own threads
## and return the results
#results = pool.map(requests.get, urls)
##close the pool and wait for the work to finish
#pool.close()
#pool.join()
# Make the Pool of workers
pool = Pool()
# Open the urls in their own threads
# and return the results
results = pool.map(requests.get, urls)
#close the pool and wait for the work to finish
pool.close()
pool.join()
t1 = time.time()
print(t1 - t0)