[Twisted-Python] How to get callback return value

Hi,all! On call main method, it call self.getName() in A.py, as I use callback, I can not get the return value correctly, I thought it's because the Asynchronous attribute, how should i do? B.py main: name=self.getName() A.py def getname(): def.callback(method1) def.callback(method2) def.callback(success) return self.name def success(name): self.name=name Thanks!

The code you included in your email doesn't make sense. Please include a full working (with errors) code sample and then people can help you. Also, I _highly_ recommend that you read this: http://krondo.com/?page_id=1327 It might as well be considered the official n00b intro to Twisted, imho.

Thanks very much. Following is the traceback message and source code. => Traceback (most recent call last): File "/home/20131203-Client/src/NodeConfigurator.py", line 250, in __slotSelectionChanged self.__showConfigurationPage(last_item, 0) File "/home/20131203-Client/src/NodeConfigurator.py", line 294, in __showConfigurationPage self.showConfigurationPageByName(itm) File "/home/20131203-Client/src/NodeConfigurator.py", line 345, in showConfigurationPageByName page.loadConfig(itm.getIDs()[0], itm.tmpConfig) File "/home/20131203-Client/src/Ui/ConfigurationPages/Page_Circle.py", line 125, in loadConfig self.textLabel_Platform.setText(platform) TypeError: QLabel.setText(QString): argument 1 has unexpected type 'NoneType' 1111fff Circle Source code: /home/20131203-Client/src/Ui/ConfigurationPages/Page_Circle.py def loadConfig(self, id, config = None): """ Load the config """ platform = node.get_platform() self.textLabel_Platform.setText(platform) /home/20131203-Client/src/node.py def get_platform(self): """ Returns node type """ self.node.addCallback(self.get_model) self.node.addCallback(self.success) return self.model def get_model(self, object): model=object.callRemote("getModel") return model def success(self, model): print '1111fff' print model self.model=model return self.model 2013/12/3 Daniel Sank <sank.daniel@gmail.com>
The code you included in your email doesn't make sense. Please include a full working (with errors) code sample and then people can help you.
Also, I _highly_ recommend that you read this:
http://krondo.com/?page_id=1327
It might as well be considered the official n00b intro to Twisted, imho.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

From reading the code you pasted in your email it really looks like you aren't using deferreds correctly. Did you read the tutorial I
this is not a complete working example. There's no executable code, and what you included doesn't make sense. When people ask for a complete working example it means that they want to try to run the same program that you're running. Just attach your actual source files to an email and send them. linked in the other email?

On Tue, Dec 3, 2013, at 12:00, 杨有秀 wrote:
def loadConfig(self, id, config = None): """ Load the config """
platform = node.get_platform() self.textLabel_Platform.setText(platform)
/home/20131203-Client/src/node.py
def get_platform(self): """ Returns node type """
self.node.addCallback(self.get_model) self.node.addCallback(self.success) return self.model
addCallback is a method of twisted.internet.defer.Deferred, but I don't think your node is a Deferred.
def get_model(self, object): model=object.callRemote("getModel") return model
This looks as though it will return a Deferred, from the callRemote. If that isn't the case, ignore everything else below. So you might write: def get_platform(self): """ Returns node type """ self.model = self.get_model() self.model.addCallback(self.success) return self.model def success(self, model): print '1111fff' return model And then you could use the value returned by get_platform (which is a Deferred) by adding a callback to it: def loadConfig(self, id, config = None): """ Load the config """ node.get_platform().addCallback(self.textLabel_Platform.setText) When the callRemote succeeds, it calls the callbacks on the Deferred. First, it passes the return value from the remote call to success(). Then it passes the return value from success() to textLabel_Platform.setText. Peter.
participants (4)
-
Daniel Sank
-
Peter Westlake
-
yangyouxiu
-
杨有秀