Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added shutdown method to handlers

  • Loading branch information...
commit 6b1c3080c33c4faffbf2025024c6e2ffb21b9d7a 1 parent 4635468
Gestiweb gestiweb authored
Showing with 19 additions and 0 deletions.
  1. +11 −0 bjsonrpc/connection.py
  2. +8 −0 bjsonrpc/handlers.py
11 bjsonrpc/connection.py
View
@@ -368,6 +368,12 @@ def _dispatch_method(self, request):
if req_method == '__delete__':
req_object = None
+ try:
+ self._objects[objectname]._shutdown()
+ except Exception:
+ print "Error when shutting down the object", type(self._objects[objectname]),":"
+ print traceback.format_exc()
+
del self._objects[objectname]
result = None
else:
@@ -552,6 +558,11 @@ def close(self):
Close the connection and the socket.
"""
try:
+ self.handler._shutdown()
+ except Exception:
+ print "Error when shutting down the handler:"
+ print traceback.format_exc()
+ try:
self._sck.shutdown(socket.SHUT_RDWR)
except socket.error:
pass
8 bjsonrpc/handlers.py
View
@@ -85,6 +85,14 @@ def _setup(self):
"""
pass
+ def _shutdown(self):
+ """
+ Internal method called when the handler is going to be destroyed.
+ You should add cleanup code here. Remember to call the parent
+ function.
+ """
+ pass # In the future, here we could have some internal clean-up code.
+
def close(self):
"""
Cleans some variables before the object is freed. _close is called
Please sign in to comment.
Something went wrong with that request. Please try again.