Created
January 21, 2015 22:29
-
-
Save nbraem/0e5178288ffd94372062 to your computer and use it in GitHub Desktop.
BaseConnector not closing all sockets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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