인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

대현님의 프로필 이미지
대현

작성한 질문수

우리를 위한 프로그래밍 : 파이썬 중급 (Inflearn Original)

병행성 - 코루틴, Yield (3-1)

StopIteration 예외 처리

작성

·

355

0

안녕하세요 선생님, @12:58에서 cr1.send(100)을 했을 때 발생하는 StopIteration을 처리하기 위해선 예외처리가 필요한것 처럼 일반적으로 코루틴은 StopIteration 처리 문구를 넣어줘야하나요?

답변 1

2

좋은사람님의 프로필 이미지
좋은사람
지식공유자

일반적으로 StopIteration은 for문 next 등올 접근 시 내부적으로 처리가 되기 때문에 

코딩시에는 사용하실일이 거의 없는 것 같습니다.

명시적으로 사용하셔도 되는 부분입니다. 사용하기 나름입니다.

Now, normally you don't see StopIteration exceptions. The reason for this is that you usually consume generators inside for loops. A for statement will automatically call next over and over until StopIteration gets raised. It will catch and suppress the StopIteration exception for you, so you don't need to mess around with try/except blocks to deal with it.

대현님의 프로필 이미지
대현

작성한 질문수

질문하기