# Need Help With Twisted Deferred

This topic is 1651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Terribly sorry. It was just a small mistake. I've fixed it. I forgot that I should have returned the deferred object. Sorry everyone.

[spoiler]

Hi everyone. Now I'm studying network programming with Python Twisted. I'm pretty familiar with deferred, and I understand asynchronous programming a little bit, but there's still this one issue I still can't solve. Let me hand you some code to understand my situation first.

from twisted.protocols import amp
from twisted.python import log

#This is just test log, so please spare me.

Login.responder(login)

When the client use callRemote to the login command, it will get the result {'username': username, 'password': username}. Everything works fine. My problem is, this login function will need to fetch some stuff from the database, which operation uses deferred objects, and the login function needs to get the result from that query, return it and yeah... I'm expecting something like this:

from twisted.protocols import amp
from twisted.python import log
from twisted.internet import defer

def test_return(self, result):
log.msg('FIRED %s!' % repr(result))

deferred = defer.Deferred()

Login.responder(login)

I'm wondering if I can catch the result caught in the last callback with the parent function, so it can return it as well. What I know is that callbacks are like a set of function calls which is started when a result is ready, and it passes its return value to the next callbacks, so I'm wondering if I can get the last result and return it with the login function. I apologize if my question isn't clear enough. I hope you people can get my question.

Thank you.

[/spoiler]

Edited by Sky Warden