2016-04-13 15:27:06 +01:00
|
|
|
# test simple async with execution
|
|
|
|
|
|
|
|
class AContext:
|
|
|
|
async def __aenter__(self):
|
|
|
|
print('enter')
|
2016-10-11 02:30:32 +01:00
|
|
|
return 1
|
2016-04-13 15:27:06 +01:00
|
|
|
async def __aexit__(self, exc_type, exc, tb):
|
2016-09-28 02:52:13 +01:00
|
|
|
print('exit', exc_type, exc)
|
2016-04-13 15:27:06 +01:00
|
|
|
|
|
|
|
async def f():
|
|
|
|
async with AContext():
|
|
|
|
print('body')
|
|
|
|
|
|
|
|
o = f()
|
|
|
|
try:
|
|
|
|
o.send(None)
|
|
|
|
except StopIteration:
|
|
|
|
print('finished')
|
2016-09-28 02:52:13 +01:00
|
|
|
|
|
|
|
async def g():
|
2016-10-11 02:30:32 +01:00
|
|
|
async with AContext() as ac:
|
|
|
|
print(ac)
|
2016-09-28 02:52:13 +01:00
|
|
|
raise ValueError('error')
|
|
|
|
|
|
|
|
o = g()
|
|
|
|
try:
|
|
|
|
o.send(None)
|
|
|
|
except ValueError:
|
|
|
|
print('ValueError')
|