“RuntimeError: generator raised StopIteration” every time I try to run app

后端 未结 5 471
执笔经年
执笔经年 2020-12-02 16:49

I am trying to run this code:

import web

urls = (
    \'/\', \'index\'
)

if __name__ == \"__main__\":
    app = web.application(urls, globals())
    app.ru         


        
5条回答
  •  悲&欢浪女
    2020-12-02 17:32

    To judge from the file paths, it looks like you're running Python 3.7. If so, you're getting caught by new-in-3.7 behavior described here:

    PEP 479 is enabled for all code in Python 3.7, meaning that StopIteration exceptions raised directly or indirectly in coroutines and generators are transformed into RuntimeError exceptions. (Contributed by Yury Selivanov in bpo-32670.)

    Before this change, a StopIteration raised by, or passing through, a generator simply ended the generator's useful life (the exception was silently swallowed). The module you're using will have to be recoded to work as intended with 3.7.

    Chances are they'll need to change:

    yield next(seq)
    

    to:

    try:
        yield next(seq)
    except StopIteration:
        return
    

提交回复
热议问题