Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8826529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:09:34+00:00 2026-06-14T07:09:34+00:00

I have a simple handler like so : @asynchronous @gen.engine def post(self): result =

  • 0

I have a simple handler like so :

@asynchronous
@gen.engine
def post(self):
    result = functionOne()
    foo = MyObject()
    bar = AnotherObject()

But I’d like for result to come back, then execute foo, then bar in a sequence. I’ve tried using nested callbacks as per http://www.tornadoweb.org/documentation/gen.html but without much luck.

thx!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:09:36+00:00Added an answer on June 14, 2026 at 7:09 am

    You are using the gen.engine, but you need to make your method calls into yield with a gen.Task calls.

    Example from a project of mine:

    customer = yield gen.Task( self.paymentService.charge, email, cardUri )
    sub = yield gen.Task( self.paymentService.schedule, customer )
    

    The above will first do the charge part then return the result and then call the schedule and return the subscription object from that call.

    The methods that you call with the gen.Task need to look like the following:

    def customer( self, email, cardUri, callback=None ):
    

    Where callback will be the function to call to actually return the value from the gen.Task.

    I have it setup to work with or without the callback so I can more easily test my methods. Which is just a simple test if callback is None or not and if it isn’t None then it gets called else it returns normally.

    gen.Engine Docs

    EDIT:

    Ok, to clarify the above it a complete function that works with gen.Tasks looks like the following.

    def delete_customer( customer_id, callback ):
        result = customerService.delete( customer_id )
    
        callback( result )
    

    The above when used in a gen.Task will look like the following.

    @gen.engine
    def perform_customer_delete( customer_id )
        result = yield gen.Task( delete_customer, customer_id )
        return result
    

    This means to call the delete_customer with the parameter customer_id and then I want the result of this function, the return, to be given to result. So, when the delete_customer function completes and sends the result of the self.customerService.delete to the callback the gen.Task will then return the value and store it in result.

    Now, you can use the result however you wish, in my example it is returned.

    For you example it looks like you want to do the following.

    @asynchronous
    @gen.engine
    def post(self):
        result = yield gen.Task( functionOne )
        foo = yield gen.Task( MyObject )
        bar = yield gen.Task( AnotherObject )
    

    This will first call the functionOne then go to the next gen.Task and execute the MyObject and so forth. But, you must follow the pattern where you have a callback parameter in your methods in order to use gen.Task correctly otherwise you cannot get the result back.

    This is where my second, confusing example, comes into play.

    In order to get around this requirement and to allow my code to work with gen.Task and without I do the following.

    def delete_customer( customer_id, callback=None ):
        result = customerService.delete_customer( customer_id )
        if callback:
            callback( result )
        return result
    

    This allows me to use the code in a lot more situations without breakage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a simple async case, handler might look like: @tornado.web.authenticated @tornado.web.asynchronous def post(self): AsyncHTTPClient().fetch(http://api.example.com/,
I have a simple AppEngine handler as follows: class TestGS(webapp2.RequestHandler): def get(self): file_name =
I have simple SSIS package in which On Error event handler I have created
I have a simple Python script that uses a signal handler for Ctl-C. If
I have a simple form using a POST method, consisting of a text box
I'm writing a simple App Engine app. I have a simple page that allows
I have a simple button in HTML like this: <input type='button' id='btnPrint' value='Print' onclick=changeStylesheet();
I have a simple Django-Piston Handler that creates a new instance of a model
I have a simple 'file download' generic handler which sets the response contenttype and
I have a simple handler that adds an ellipse to an empty Silverlight canvas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.