Handle generator exceptions in its consumer

前端 未结 8 1625
迷失自我
迷失自我 2020-11-29 10:07

This is a follow-up to Handle an exception thrown in a generator and discusses a more general problem.

I have a function that reads data in different formats. All fo

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 10:39

    Actually, generators are quite limited in several aspects. You found one: the raising of exceptions is not part of their API.

    You could have a look at the Stackless Python stuff like greenlets or coroutines which offer a lot more flexibility; but diving into that is a bit out of scope here.

提交回复
热议问题