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

  • Home
  • SEARCH
  • 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 7966997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:34:55+00:00 2026-06-04T06:34:55+00:00

When i call DoSomething() method from my test method, i expect it to block

  • 0

When i call DoSomething() method from my test method, i expect it to block on the yield in Connect() but it doesnt, it returns a not called yet deferred.

Class Foo:
    @defer.inlineCallbacks
    def Connect(self):
        amqpConfig = AmqpConfig(self.config.getConfigFile())
        self.amqp = AmqpFactory(amqpConfig)

        try:
            # First Deferred
            d = self.amqp.connect()
            # Second Deferred
            d.addCallback(lambda ign: self.amqp.getChannelReadyDeferred()) 

            # Block until connecting and getting an AMQP channel
            yield d
        except Exception, e:
            self.log.error('Cannot connect to AMQP broker: %s', e)

    def DoSomething(self):
        c = self.Connect()
        # None of the deferreds were fired, c.called is False

How can i let it block till the second (and last) deferred is called ?

  • 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-04T06:34:56+00:00Added an answer on June 4, 2026 at 6:34 am

    Your call to self.Connect() in DoSomething() is supposed to return a not-yet-fired Deferred; that’s how inlineCallbacks works. The code at the beginning of Connect() should have been called, but once it hit the first yield it just returned its Deferred to your caller. Later on, when the AMQP channel is acquired, that Deferred will fire.

    If you want the DoSomething() call to… do something 🙂 after the c Deferred fires, and you don’t want to make DoSomething() into another inlineCallbacks method, then just use the Deferred in the normal way: addCallback() and friends. Example:

    def DoSomething(self):
        c = self.Connect()
        c.addCallback(self.handle_getting_amqp_channel)
        c.addErrback(self.this_gets_called_if_something_went_wrong)
        return c
    

    For more information on how Twisted Deferreds work, see http://twistedmatrix.com/documents/current/core/howto/defer.html . Hope this helps.

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

Sidebar

Related Questions

I call the following function with a mouseover event but it's not working. My
Lets say I have the below method called DoSomething. When writing unit tests how
I have a simple object, of type ObjectX, with a simple method called doSomething().
How can I call a method in the code behind from a jQuery post
I'm trying to call a java method from native C code in an Android
I want to test whether the following method is called with in my Javascript
I am trying to call my BHO method from the javascript. The problem is
Can you intercept a method call in Perl, do something with the arguments, and
When calling an ASP.Net PageMethod, we call it as follows: function doSomething(htmlElement) { PageMethods.GetText(onSuccess,
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my

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.