Skip to content

Add a RqlCursorEmpty exception to the python driver #3974

Closed

Description

@Tryneus

Tornado does not play well with StopIteration exceptions. In order to maintain compatibility I would suggest having the following errors:

RqlCursorEmpty, inherits from RqlError

DefaultCursorEmpty, inherits from RqlCursorEmpty and StopIteration

  • this is thrown by DefaultCursor during iteration or next when the stream is exhausted (but no other errors occurred)

TornadoCursorEmpty inherits from RqlCursorEmpty

  • this is thrown by TornadoCursor futures when yielded and the stream is exhausted (but no other errors occurred)

Activity

  1. added this to the 2.0 milestone on Mar 24, 2015
  2. danielmewes commented on Mar 24, 2015

    @danielmewes
    Member

    Just to make sure I understand the issue:
    You mentioned in the other thread

    Unfortunately, if the user doesn't catch this, it interacts poorly with Tornado, which assumes the StopIteration means that the coroutine has finished.

    Is that a special meaning of StopIteration in Tornado? What happens with other exceptions that the user doesn't catch? Would they also terminate the coroutine?

  3. Tryneus commented on Mar 24, 2015

    @Tryneus
    MemberAuthor

    @danielmewes, yes, you can see in the source here, the implementation of _make_coroutine_wrapper treats a raise StopIteration() the same as a raise gen.Return(None). Other exceptions will be put into the returned future and will be re-raised when those futures are yielded.

  4. danielmewes commented on Mar 24, 2015

    @danielmewes
    Member

    Got it, thanks!

  5. danielmewes commented on Mar 24, 2015

    @danielmewes
    Member

    Your proposed change makes total sense then. 👍

  6. v3ss0n commented on Mar 25, 2015

    @v3ss0n

    Leaving a message here to track this.
    I am going to test rethinkdb + Tornado this weekend.
    So for now , user need to catch the StopIteration right?

  7. danielmewes commented on Mar 25, 2015

    @danielmewes
    Member

    @v3ss0n (Edit: removed possible wrong answer). I'm actually not sure if you can catch the StopIteration at the moment (pinging @Tryneus ).
    You might want to wait until this is fixed.

    (you can track threads by clicking the "Subscribe" button on the right by the way)

  8. Tryneus commented on Mar 25, 2015

    @Tryneus
    MemberAuthor

    This has been approved and merged to next in commit 2171061, and cherry-picked into v2.0.x in commit c08b40d. Review was 2742. Will be in release 2.0.

    The proper way to iterate over a TornadoCursor object is now:

    while (yield cursor.fetch_next()):
        item = yield cursor.next()

    or

    try:
        while True:
            item = yield cursor.next()
    except r.RqlCursorEmpty:
        pass

    Both cursor.next() and cursor.fetch_next() take a wait optarg to specify how long to wait before timing out (after which a RqlTimeoutError exception is raised). This optarg defaults to True, which will wait indefinitely. cursor.fetch_next() only exists on the TornadoCursor implementation.

    @v3ss0n, thanks for your interest, let us know if you have any problems or suggestions after trying it out!

  9. v3ss0n commented on Apr 2, 2015

    @v3ss0n

    ah i forgot that. trying now

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions