File tree 2 files changed +18
-7
lines changed
2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -393,14 +393,16 @@ async def start_server():
393
393
loop = self .loop ,
394
394
start_serving = False )
395
395
396
- fut = asyncio .ensure_future (srv .serve_forever (), loop = self .loop )
397
- await asyncio .sleep (0 , loop = self .loop )
398
- self .assertTrue (srv .is_serving ())
396
+ async with srv :
397
+ fut = asyncio .ensure_future (srv .serve_forever (),
398
+ loop = self .loop )
399
+ await asyncio .sleep (0 , loop = self .loop )
400
+ self .assertTrue (srv .is_serving ())
399
401
400
- fut .cancel ()
401
- with self .assertRaises (asyncio .CancelledError ):
402
- await fut
403
- self .assertFalse (srv .is_serving ())
402
+ fut .cancel ()
403
+ with self .assertRaises (asyncio .CancelledError ):
404
+ await fut
405
+ self .assertFalse (srv .is_serving ())
404
406
405
407
self .loop .run_until_complete (start_server ())
406
408
Original file line number Diff line number Diff line change @@ -48,6 +48,15 @@ cdef class Server:
48
48
49
49
# Public API
50
50
51
+ @cython.iterable_coroutine
52
+ async def __aenter__(self ):
53
+ return self
54
+
55
+ @cython.iterable_coroutine
56
+ async def __aexit__(self , * exc):
57
+ self .close()
58
+ await self .wait_closed()
59
+
51
60
def __repr__ (self ):
52
61
return ' <%s sockets=%r >' % (self .__class__.__name__ , self .sockets)
53
62
You can’t perform that action at this time.
0 commit comments