Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Request for code review: Tornado AsyncResult
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
A. Jesse Jiryu Davis  
View profile  
 More options Oct 12 2012, 12:14 am
From: "A. Jesse Jiryu Davis" <ajesseda...@gmail.com>
Date: Thu, 11 Oct 2012 21:14:25 -0700 (PDT)
Local: Fri, Oct 12 2012 12:14 am
Subject: Request for code review: Tornado AsyncResult

Hi all, I'm starting a cute side-project called "Toro" where I adapt
Python's and Gevent's synchronization primitives to Tornado. The first
primitive is Gevent's AsyncResult<http://www.gevent.org/gevent.event.html#gevent.event.AsyncResult>.
My API is like:

class AsyncResult:
    def get(self, callback, timeout):
        """Get the value that's been set.
        If callback provided, execute it with the value after set() is run,
or execute it
        with None after timeout."""

    def set(self, value):
        """Set the value, wake all waiters."""

The idea is for an async function to "block" waiting for another function
to set a result:

@gen.engine
def get_result(async_result):
    value = yield gen.Task(async_result.get)
    do_something_with(value)

Would some Tornado expert like to code-review my implementation so far, *particularly
regarding exception-handling*? It's just a 60-line file and a 30-line test:

https://gist.github.com/3877210

I'm particularly anxious to know if people think my exception-handling test
expects the proper behavior, and if my use of stack_context.wrap() on line
69 is correct:

https://gist.github.com/3877210#L69


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Darnell  
View profile  
 More options Oct 13 2012, 1:39 am
From: Ben Darnell <b...@bendarnell.com>
Date: Fri, 12 Oct 2012 22:39:17 -0700
Local: Sat, Oct 13 2012 1:39 am
Subject: Re: [tornado] Request for code review: Tornado AsyncResult
Looks good to me.

On Thu, Oct 11, 2012 at 9:14 PM, A. Jesse Jiryu Davis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roey Berman  
View profile  
 More options Oct 13 2012, 5:24 am
From: Roey Berman <roey.ber...@gmail.com>
Date: Sat, 13 Oct 2012 11:24:41 +0200
Local: Sat, Oct 13 2012 5:24 am
Subject: Re: [tornado] Request for code review: Tornado AsyncResult

There's one issue with your stack_context handling.

It's good that you stack_context.wrap() the callback when setting it in
_Waiter.
You'll have to call that callback inside a NullContext() to prevent a
stack_context leak in set().
Take this scenario for example.
set()'s ExceptionStackContext will catch the exception in raise_callback().

---
        def set_result():
            with
stack_context.ExceptionStackContext(catch_set_result_exception):
                result.set('hello')

        def callback(value):
            outcomes['value'] = value
            loop.add_callback(raise_callback)

        def raise_callback():
            assert False

        def catch_set_result_exception(type, value, traceback):
            outcomes['set_result_exc'] = type
            return True

        result.get(callback)

        loop.add_timeout(time.time() + .01, set_result)
        loop.start()
        self.assertEqual(outcomes['value'], 'hello')
        self.assertNotEqual(outcomes['set_result_exc'], AssertionError)

On Fri, Oct 12, 2012 at 6:14 AM, A. Jesse Jiryu Davis <ajesseda...@gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ben Darnell  
View profile  
 More options Oct 13 2012, 12:35 pm
From: Ben Darnell <b...@bendarnell.com>
Date: Sat, 13 Oct 2012 09:35:31 -0700
Local: Sat, Oct 13 2012 12:35 pm
Subject: Re: [tornado] Request for code review: Tornado AsyncResult
Good catch.  This is actually changing in Tornado 3.0, so you won't
need the NullContext in the future.  This leak happens when a callback
wrapped with no contexts is run under a StackContext; if both the
calls to get and set had separate contexts the leak wouldn't happen.

-Ben


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
A. Jesse Jiryu Davis  
View profile  
 More options Oct 14 2012, 11:06 am
From: "A. Jesse Jiryu Davis" <ajesseda...@gmail.com>
Date: Sun, 14 Oct 2012 08:06:32 -0700 (PDT)
Local: Sun, Oct 14 2012 11:06 am
Subject: Re: [tornado] Request for code review: Tornado AsyncResult

Brilliant, thanks Roey. I've updated:

https://gist.github.com/3877210/

I knew I was probably missing something. =)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »