File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ from concurrent .futures import ThreadPoolExecutor
2
+ import requests
3
+
4
+
5
+ def task (url , timeout = 10 ):
6
+ return requests .get (url , timeout = timeout )
7
+
8
+
9
+ def req (pool ):
10
+ URLS = ["https://www.baidu.com" , "http://www.qq.com" , "https://www.tencent.com" ]
11
+ results = pool .map (task , URLS )
12
+ for result in results :
13
+ print ("{}, {}" .format (result .url , len (result .content )))
14
+
15
+
16
+ def insert_dic (dic , key , value ):
17
+ dic [key ] = value
18
+
19
+
20
+ def remove_dic (dic , key ):
21
+ del dic [key ]
22
+
23
+
24
+ def start_operation (dic , pool ):
25
+ pool .submit (insert_dic , dic , "hello" , "world" )
26
+
27
+
28
+ def main ():
29
+ pool = ThreadPoolExecutor (max_workers = 3 )
30
+ # req(pool)
31
+ dic = {}
32
+ start_operation (dic , pool )
33
+ print (dic )
34
+
35
+
36
+ if __name__ == '__main__' :
37
+ main ()
You can’t perform that action at this time.
0 commit comments