Skip to content

Commit 902d623

Browse files
committed
多线程增加阻塞
1 parent 4d962f5 commit 902d623

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pachong1.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,20 @@ def test(page):
8989

9090

9191
if __name__ == '__main__':
92+
threads = []
9293
for page in range(1, 5):
9394

9495
# 启动多线程,每个线程分别抓取不同的页
95-
threading.Thread(target=test, args=(page,)).start()
96+
# threading.Thread(target=test, args=(page,)).start()
97+
t = threading.Thread(target=test, args=(page,))
98+
threads.append(t)
9699

97100
# 单进程很慢,一页接着一页抓取
98101
# test(page)
102+
103+
for i in threads:
104+
i.start()
105+
106+
for i in threads:
107+
i.join()
108+
print 'All is Done'

0 commit comments

Comments
 (0)