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

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

by 루시아누 하말류, 강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from 전문가를 위한 파이썬(2판)
911
21
비동기 프로그래밍
다음 코드를 보자.
result = []
async for i in aiter():
if i % 2:
result.append(i)
앞 코드는 다음과 같이 바꿀 수 있어야 한다고 누구나 생각한다.
result = [i async for i in aiter() if i % 2]
게다가 네이티브 코루틴
fun( )
이 있을 때 다음과 같이 작성할 수 있어야 한다.
result = [await fun() for fun in funcs]
TIP
지능형 리스트에서
await
를 사용하는 것은
asyncio.gather()
를 사용하는 것과 비슷하다. 그러
나 선택적인 인수
return_exceptions
덕분에
gather()
를 사용하면 예외를 더 잘 처리할 수 있다. 칼
렙 해팅은 언제나
return_exceptions=True
로 설정하기를 권장한다(기본값은
False
다). 자세한 내용은
asyncio.gather()
문서(
https://fpy.li/21-48
)를 참조하라.
마술과도 같은 비동기 콘솔로 다시 돌아가 보자.
>>> names = ‘python.org rust-lang.org golang.org no-lang.invalid’.split()
>>> names = sorted(names)
>>> coros = [probe(name) for name ...
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