質問編集履歴
2
自己解決した部分の削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
for loop 中の id(resp) が変っています。この場合、resp が新しく作成されたタイミングで自動的に timeout するのでしょうか?
|
4
4
|
|
5
|
-
shadow variable を許す言語なので resp が破棄されるのが関数を出るタイミングだったと記憶しています。そのため、以下の Keep-Alive のセクションを読む限り大量に timeout していない resp が残ったままになるのではないかと考えています。
|
5
|
+
~~shadow variable を許す言語なので resp が破棄されるのが関数を出るタイミングだったと記憶しています。そのため、以下の Keep-Alive のセクションを読む限り大量に timeout していない resp が残ったままになるのではないかと考えています。~~
|
6
|
-
https://requests.readthedocs.io/en/latest/user/advanced/#session-objects
|
6
|
+
https://requests.readthedocs.io/en/latest/user/advanced/#session-objects
|
7
7
|
|
8
8
|
for loop の中で get() の後に resp.close() した方が良いのでしょうか?しかし、そのようにするとストリーミング処理した意味がなくなってしまうのではないかと思うのですが...
|
9
9
|
|
1
typo と timeout を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,15 +11,15 @@
|
|
11
11
|
|
12
12
|
```
|
13
13
|
ses = requests.Session()
|
14
|
-
resp = ses.get(self.URLS['short_ratio'], stream=True)
|
14
|
+
resp = ses.get(self.URLS['short_ratio'], stream=True, timeout=3)
|
15
15
|
resp.encoding = resp.apparent_encoding
|
16
16
|
|
17
17
|
url_chars = '[0-9a-zA-Z\/\-\_]*'
|
18
18
|
urls_xls = []
|
19
19
|
urls_xls += re.findall('{0}\.xls?'.format(url_chars), resp.text)
|
20
20
|
|
21
|
-
for p in re.findall('{0}\d\d-archives-\d\d\.html?'.format(url_chars)
|
21
|
+
for p in re.findall('{0}\d\d-archives-\d\d\.html?'.format(url_chars):
|
22
|
-
resp = ses.get('{0}{1}'.format(self.BASE_URL, p), stream=True)
|
22
|
+
resp = ses.get('{0}{1}'.format(self.BASE_URL, p), stream=True, timeout=3)
|
23
23
|
print(id(ses), id(resp))
|
24
24
|
print(resp.cookies)
|
25
25
|
resp.encoding = resp.apparent_encoding
|