오늘 새벽, 작년에 보냈던 Async-SQLModel 관련 PR에 대한 답변을 받았다.
그때 SQLModel에 비동기 필드 접근을 위한 대안을 제안했었는데, 이번에 공식적으로 반려되었다.
My personal opinions is that we don't need this.This gives an alternative to lazy load instructions\declarations, but the syntax is not nice:
- we have to declare all types as Awaitable[str]
- we have to add await every time we access field
Working with async SQLAlchemy (and SQLModel) is more difficult, but even with suggested changes people will still need to learn it to avoid issues with accessing fields when DB session has already been closed, and other situations.Also, lazy loading instructions\declarations will be more efficient in terms of performance.
요약하자면, 사용 방식이 번거롭고 성능상 이점도 크지 않다는 이유로 기능이 채택되지 않았다.
사실 나도 해당 기능이 별로 쓰이지 않을 거라고 예상하고 있었다.
답변에 나왔듯이 SQLAlchemy를 포함한 대부분의 orm에서 코루틴(이벤트 루프성 비동기)을 사용하는 건 여전히 불편하고, 해결되진 않아 그냥 코루틴을 잘 안쓰기 때문이다.
현재의 나는 그냥 orm에 async를 쓰지 않는 게 좋다고 생각한다.
코루틴을 활용한 비동기 프로그래밍은 멋지긴 하지만, orm을 이용한다면 멀티 스레딩을 최대한 활용하는 것이 일단의 최선인것 같다.
마침 3.13, 3.14에서 최신의 파이썬은 GIL을 없애는 추세니 기대해본다.
Add an AwaitableField for accessing sqlmodel field asynchronously by 2jun0 · Pull Request #872 · fastapi/sqlmodel
I'm not that good at English. So, if there's anything you don't understand, please feel free to reply. Currently, accessing some fields asynchronously is hard. I often encounter the Mis...
github.com
'프로그래밍 > 파이썬' 카테고리의 다른 글
| [Async-SQLModel] SQLModel서 비동기 프로그래밍시 발생하는 문제의 대안 (1) | 2024.04.03 |
|---|---|
| 파이썬, if문보다 try~expect이 더 좋다? (0) | 2023.08.14 |
| MongoDB의 Date와 python의 datetime (1) | 2023.08.10 |