Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit 1bbb7ab

Browse files
committed
flags2_asyncio_executor.py closing http request\n\nSometime raises RuntimeError: Event loop is closed
1 parent 90daf6e commit 1bbb7ab

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

‎17-futures/countries/flags2_asyncio_executor.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import asyncio
88
import collections
9+
import contextlib
910

1011
import aiohttp
1112
from aiohttp import web
@@ -28,15 +29,17 @@ def __init__(self, country_code):
2829
def get_flag(base_url, cc):
2930
url = '{}/{cc}/{cc}.gif'.format(base_url, cc=cc.lower())
3031
resp = yield from aiohttp.request('GET', url)
31-
if resp.status == 200:
32-
image = yield from resp.read()
33-
return image
34-
elif resp.status == 404:
35-
raise web.HTTPNotFound()
36-
else:
37-
raise aiohttp.HttpProcessingError(
38-
code=resp.status, message=resp.reason,
39-
headers=resp.headers)
32+
with contextlib.closing(resp):
33+
if resp.status == 200:
34+
image = yield from resp.read()
35+
return image
36+
elif resp.status == 404:
37+
raise web.HTTPNotFound()
38+
else:
39+
raise aiohttp.HttpProcessingError(
40+
code=resp.status, message=resp.reason,
41+
headers=resp.headers)
42+
4043

4144
# BEGIN FLAGS2_ASYNCIO_EXECUTOR
4245
@asyncio.coroutine

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /