@@ -61,7 +61,7 @@ def __init__(self, roots,
6161 self .q = Queue (loop = self .loop )
6262 self .seen_urls = set ()
6363 self .done = []
64- self .connector = aiohttp .TCPConnector (loop = self .loop )
64+ self .session = aiohttp .ClientSession (loop = self .loop )
6565 self .root_domains = set ()
6666 for root in roots :
6767 parts = urllib .parse .urlparse (root )
@@ -83,7 +83,7 @@ def __init__(self, roots,
8383
8484 def close (self ):
8585 """Close resources."""
86- self .connector .close ()
86+ self .session .close ()
8787
8888 def host_okay (self , host ):
8989 """Check if a host should be crawled.
@@ -172,11 +172,9 @@ def fetch(self, url, max_redirect):
172172 exception = None
173173 while tries < self .max_tries :
174174 try :
175- response = yield from aiohttp .request (
176- 'get' , url ,
177- connector = self .connector ,
178- allow_redirects = False ,
179- loop = self .loop )
175+ response = yield from self .session .get (
176+ url , allow_redirects = False )
177+
180178 if tries > 1 :
181179 LOGGER .info ('try %r for %r success' , tries , url )
182180
@@ -229,6 +227,8 @@ def fetch(self, url, max_redirect):
229227 self .q .put_nowait ((link , self .max_redirect ))
230228 self .seen_urls .update (links )
231229
230+ yield from response .release ()
231+
232232 @asyncio .coroutine
233233 def work (self ):
234234 """Process queue items forever."""
0 commit comments