Movatterモバイル変換


[0]ホーム

URL:


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.

Commit1bbb7ab

Browse files
committed
flags2_asyncio_executor.py closing http request\n\nSometime raises RuntimeError: Event loop is closed
1 parent90daf6e commit1bbb7ab

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
importasyncio
88
importcollections
9+
importcontextlib
910

1011
importaiohttp
1112
fromaiohttpimportweb
@@ -28,15 +29,17 @@ def __init__(self, country_code):
2829
defget_flag(base_url,cc):
2930
url='{}/{cc}/{cc}.gif'.format(base_url,cc=cc.lower())
3031
resp=yieldfromaiohttp.request('GET',url)
31-
ifresp.status==200:
32-
image=yieldfromresp.read()
33-
returnimage
34-
elifresp.status==404:
35-
raiseweb.HTTPNotFound()
36-
else:
37-
raiseaiohttp.HttpProcessingError(
38-
code=resp.status,message=resp.reason,
39-
headers=resp.headers)
32+
withcontextlib.closing(resp):
33+
ifresp.status==200:
34+
image=yieldfromresp.read()
35+
returnimage
36+
elifresp.status==404:
37+
raiseweb.HTTPNotFound()
38+
else:
39+
raiseaiohttp.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)

[8]ページ先頭

©2009-2025 Movatter.jp