推 lycantrope: 這邊用return的話db.close()會在return 之前執行 03/15 23:15
→ lycantrope: yield只是暫時跳出function回傳,之後還會跳回來執行 03/15 23:16
→ lycantrope: db.close() 03/15 23:16
推 TuCH: 我也很好奇 fastapi 什麼時候會進finally: db.close 03/16 09:02
推 lycantrope: get_db StopIteration 或是被del 都會執行finally 03/16 09:56
→ lycantrope: 有點類似另類的context manager 覺得酷可以學起來w 03/16 09:58
推 poototo: with的一種語法糖 03/16 10:48
推 TuCH: 我覺得fastapi 的 Depends 也是蠻神奇的 也是不知道怎麼進 03/16 12:51
推 hanfadacai: 這個之前有用到 但後來用忘記用法 只知道跟return很像 03/17 17:48
→ single4565: 可能幫助 03/19 15:16
→ mantour: try: ... finally: ... 才是比較基本的寫法吧? with 應 03/23 00:47
→ mantour: 該是後來才加進去的語法(PEP 343) 03/23 00:47