File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ from functools import partial , Placeholder as _
2+
3+ import asyncio
4+
5+ print (asyncio .Future ) # Will show if it's the C or Python version
6+ print (asyncio .Task )
7+
8+ def callback_no_exc (fut , idx ):
9+ print (f"callback_no_throw: { idx } " )
10+
11+
12+ def callback_with_exc (fut ):
13+ print ("callback_with_exception" )
14+ raise RuntimeError ("TEST EXCEPTION" )
15+
16+
17+ async def func (fut ):
18+ try :
19+ print ("func: entered" )
20+ await fut
21+ print ("func: done" )
22+ except Exception as exc :
23+ print (f"func: EXCEPTION: { exc } " )
24+
25+
26+ async def main ():
27+ loop = asyncio .get_running_loop ()
28+ loop .set_task_factory (asyncio .eager_task_factory )
29+ fut = asyncio .Future (loop = loop )
30+ fut .add_done_callback (partial (callback_no_exc , _ , 1 ))
31+ fut .add_done_callback (callback_with_exc )
32+ fut .add_done_callback (partial (callback_no_exc , _ , 2 ))
33+ loop .create_task (func (fut ))
34+ await asyncio .sleep (1 )
35+ print ("main: before set_result" )
36+ fut .eager_set_result (None )
37+ print ("main: set_result done" )
38+ await asyncio .sleep (1 )
39+ print ("main: done" )
40+
41+
42+ asyncio .run (main ())
You can’t perform that action at this time.
0 commit comments