Skip to content

Commit 8d12225

Browse files
committed
Fix compatibility with asyncio 3.4.1+ #170
1 parent 5f2b2c0 commit 8d12225

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

CHANGES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGES
22
=======
33

4+
0.9.3 (10-30-2014)
5+
------------------
6+
7+
- Fix compatibility with asyncio 3.4.1+ #170
8+
9+
0.9.2 (10-16-2014)
10+
------------------
11+
412
- Improve redirect handling #157
513

614
- Send raw files as is #153

aiohttp/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,12 @@ def write_bytes(self, request, reader):
515515
'Can not write request body for %s' % self.url))
516516
else:
517517
try:
518-
request.write_eof()
518+
ret = request.write_eof()
519+
# NB: in asyncio 3.4.1+ StreamWriter.drain() is coroutine
520+
# see bug #170
521+
if (asyncio.iscoroutine(ret) or
522+
isinstance(ret, asyncio.Future)):
523+
yield from ret
519524
except Exception as exc:
520525
reader.set_exception(
521526
aiohttp.ClientConnectionError(

aiohttp/server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,10 @@ def start(self):
219219
self.log_debug('Ignored premature client disconnection.')
220220
break
221221
except errors.HttpException as exc:
222-
self.handle_error(exc.code, message, None, exc, exc.headers)
222+
yield from self.handle_error(exc.code, message,
223+
None, exc, exc.headers)
223224
except Exception as exc:
224-
self.handle_error(500, message, None, exc)
225+
yield from self.handle_error(500, message, None, exc)
225226
finally:
226227
if self.transport is None:
227228
self.log_debug('Ignored premature client disconnection.')
@@ -290,9 +291,10 @@ def handle_error(self, status=500,
290291
response.send_headers()
291292

292293
response.write(html)
293-
response.write_eof()
294+
drain = response.write_eof()
294295

295296
self.log_access(message, None, response, time.time() - now)
297+
return drain
296298
finally:
297299
self.keep_alive(False)
298300

examples/mpsrv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def handle_request(self, message, payload):
9797
except OSError:
9898
response.write(b'Cannot open')
9999

100-
response.write_eof()
100+
yield from response.write_eof()
101101
if response.keep_alive():
102102
self.keep_alive(True)
103103

examples/wssrv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def handle_request(self, message, payload):
107107
except OSError:
108108
response.write(b'Cannot open')
109109

110-
response.write_eof()
110+
yield from response.write_eof()
111111
if response.keep_alive():
112112
self.keep_alive(True)
113113

0 commit comments

Comments
 (0)