Author: andar
Revision: 5440
Log:
If a exported method returns a deferred, the rpcserver will now wait
for it to fire before sending either the RPC_RESPONSE or RPC_ERROR message back
to the client
Diff:
Modified: trunk/deluge/core/rpcserver.py
===================================================================
--- trunk/deluge/core/rpcserver.py 2009-07-02 15:40:13 UTC (rev 5439)
+++ trunk/deluge/core/rpcserver.py 2009-07-02 18:10:13 UTC (rev 5440)
@@ -42,7 +42,7 @@
import traceback
from twisted.internet.protocol import Factory, Protocol
-from twisted.internet import ssl, reactor
+from twisted.internet import ssl, reactor, defer
from OpenSSL import crypto, SSL
from types import FunctionType
@@ -272,8 +272,24 @@
if not isinstance(e, DelugeError):
log.exception("Exception calling RPC request: %s", e)
else:
- self.sendData((RPC_RESPONSE, request_id, ret))
+ # Check if the return value is a deferred, since we'll need to
+ # wait for it to fire before sending the RPC_RESPONSE
+ if isinstance(ret, defer.Deferred):
+ def on_success(result):
+ self.sendData((RPC_RESPONSE, request_id, ret))
+ return result
+ def on_fail(failure):
+ try:
+ failure.raiseException()
+ except Exception, e:
+ sendError()
+ return failure
+
+ ret.addCallbacks(on_success, on_fail)
+ else:
+ self.sendData((RPC_RESPONSE, request_id, ret))
+
class RPCServer(component.Component):
"""
This class is used to handle rpc requests from the client. Objects are
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---