Skip to content

Instantly share code, notes, and snippets.

@nbraem
Created January 21, 2015 22:29
Show Gist options
  • Save nbraem/0e5178288ffd94372062 to your computer and use it in GitHub Desktop.
Save nbraem/0e5178288ffd94372062 to your computer and use it in GitHub Desktop.
BaseConnector not closing all sockets
import asyncio
import traceback
from aiohttp import *
def test():
connector = TCPConnector()
finished = []
@asyncio.coroutine
def make_request():
r = yield from request('get', 'http://yahoo.com', connector=connector)
finished.append(r)
tasks = [asyncio.async(make_request()) for _ in range(100)]
def cancel():
while not finished:
yield from asyncio.sleep(0.5)
print("cancelling tasks")
for t in tasks:
t.cancel()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.wait([asyncio.async(cancel())] + tasks))
print("DONE")
loop.run_forever()
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment