New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More intuitive coroutine exit #2

andreikop opened this Issue Dec 3, 2013 · 2 comments


None yet
2 participants

andreikop commented Dec 3, 2013

In your examples you use next piece of code:

finally:  # could use `except GeneratorExit` but `finally` is more illustrative

I would say, that finally is also not very illustrative. How about adding exception CouroutineCancelled to the txcoroutine API and throwing it to generator function with
So, couroutine would look this way:

  def do_job()
      while True:
        yield do_something()
    except CoroutineCancelled:
      print 'Done!'

You may also create alias CoroutineCancelled for GeneratorExit in your library, and continue using generator.close(). In this case existing code, which uses txcoroutine, will not be broken.

Thanks for the cool library!


This comment has been minimized.


eallik commented Dec 6, 2013

I'm glad to see somebody is finding the library useful! :)

However, can you please elaborate a bit on the purpose of such change? What would this CoroutineCancelled exception add to the picture? What could you do that you cannot do now?

Let me also point out that finally: is not the same as except GeneratorExit:—the former will be executed no matter what; exept GeneratorExit only when GeneratorExit is raised.


This comment has been minimized.

andreikop commented Dec 6, 2013

All works fine. This is only about code readability.

You are right, that finally and except GeneratorExit is not the same. I use except .. to write logs 'Process finished successfully'.
But, catching GeneratorExit looks not intuitive, I'm not sure if new guys who haven't read your post about @coroutine would understand this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment