Skip to Content
전문가를 위한 파이썬(2판)
book

전문가를 위한 파이썬(2판)

by 루시아누 하말류, 강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from 전문가를 위한 파이썬(2판)
947
22
동적 속성과 프로퍼티
예제
22-16
키 공유 최적화를 활용하도록
__
init
__()
에 정의된 저장소
class Event(Record):
def __init__(self, **kwargs):
self.__speaker_objs = None
super().__init__(**kwargs)
# 중간의 15줄 생략...
@property
def speakers(self):
if self.__speaker_objs is None:
spkr_serials = self.__dict__[‘speakers’]
fetch = self.__class__.fetch
self.__speaker_objs = [fetch(f’speaker.{key}’)
for key in spkr_serials]
return self.__speaker_objs
[예제
22
-
15
]와 [예제
22
-
16
]은 레거시 파이썬 코드베이스에서 상당히 자주 볼 수 있는 간단
한 캐싱 기법을 보여 준다. 그러나 멀티스레드 프로그램에서는 이렇게 직접 구현한 캐싱 코드
가 경쟁 조건을 일으켜 데이터를 훼손할 수 있다. 이전에 캐시되지 않은 프로퍼티를 두 스레드
가 동시에 읽으려 할 때, 첫 번째 스레드가 캐시 속성 (이 예제에서의
__speaker_objs
)을 계
산하고 두 번째 스레드는 아직 완성되지 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

전문가를 위한 리액트

전문가를 위한 리액트

테자스 쿠마르
고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트

Publisher Resources

ISBN: 9791169211772