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 6832261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:50:15+00:00 2026-05-26T22:50:15+00:00

I am trying to perform a simple callback sequence in twisted. The idea is

  • 0

I am trying to perform a simple callback sequence in twisted. The idea is that I login to a service, and when the login has succeeded, I start sending commands. This is my code:

from   twisted.internet          import reactor, defer

class MyService:

    def __init__ (self):
        self.handle = None

    def login(self):
        def onConnect(handle):
            self.handle = handle
            return
        df = defer.Deferred().addCallback(onConnect)
        reactor.callLater(2, df.callback, "dummyhandle")
        return df

    def sendCommand(self, command):
        def onResult(result):
            print result
            return result

        if self.handle == None:
            print "Not logged in"
            return
        else:
            df = defer.Deferred().addCallback(onResult, result ="xxx")
        return df

my = MyService ()

my.login().addCallback(my.sendCommand, command = "format")
reactor.run()

Running that code produces the following stacktrace:

Unhandled error in Deferred: Traceback (most recent call last):   File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 1179, in mainLoop
    self.runUntilCurrent()   File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py", line 778, in runUntilCurrent
    call.func(*call.args, **call.kw)   File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 280, in callback
    self._startRunCallbacks(result)   File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 354, in _startRunCallbacks
    self._runCallbacks()
--- <exception caught here> ---   File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 371, in _runCallbacks
    self.result = callback(self.result, *args, **kw) exceptions.TypeError: sendCommand() got multiple values for keyword argument 'command'

The important thing here is that sendCommand does not need the result of the login, but different data. It needs that login has completed (that is why I want it in the callback chain), but it is not interested on the result of the login (as long as it is not an error, which will be handled in the error chain anyway).

What am I doing wrong here?

  • 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-05-26T22:50:15+00:00Added an answer on May 26, 2026 at 10:50 pm

    Easy, the handler must have result as its first argument:

    def sendCommand(self, in_result, command):
        do_the_stuff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to perform a simple operation that i have done alot in
Trying to perform a very simple task here. I have an <ol> that contains
I'm trying to perform a simple LINQ query on the Columns property of a
I'm trying to perform a simple INSERT and return the identity (auto-incrementing primary key).
Trying to perform a single boolean NOT operation, it appears that under MS SQL
im trying to perform a simple database insert from a submission on a SilverLight
I am trying to perform a simple URLRewriting. if you visit azamsharp.com it will
I'm a newbie to WCF, trying to perform relatively simple task. I'm trying to
I am trying to use an HQL to perform a simple update in hibernate,
I'm trying to perform a simple animation using Cocoa. One button causes an image

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.