Loading sjrpc/server/simple.py +16 −4 Original line number Diff line number Diff line import gc import ssl import time import errno import socket import select import weakref import logging import threading from sjrpc.core import RpcConnection import pyev Loading Loading @@ -62,6 +62,16 @@ class RpcServer(object): conn = self._wrap(sock) self.register(conn) def _clean_conn(self, ref): ''' Callback called by weakref when an object is about to be collected by garbage collector. ''' try: self._clients.remove(ref) except KeyError: pass # # Public methods: # Loading @@ -72,7 +82,10 @@ class RpcServer(object): :param conn: the connection to register. ''' self._clients.add(conn) self._clients.add(weakref.ref(conn, self._clean_conn)) gc.collect() # Force a manual garbage collection to avoid memory leak # with RpcConnections. This is maybe not required but I # need to read docs about python's gc and circular refs. def unregister(self, conn, shutdown=False): ''' Loading @@ -85,7 +98,6 @@ class RpcServer(object): if conn in self._clients: if shutdown: conn.shutdown() self._clients.remove(conn) def run(self): ''' Loading Loading
sjrpc/server/simple.py +16 −4 Original line number Diff line number Diff line import gc import ssl import time import errno import socket import select import weakref import logging import threading from sjrpc.core import RpcConnection import pyev Loading Loading @@ -62,6 +62,16 @@ class RpcServer(object): conn = self._wrap(sock) self.register(conn) def _clean_conn(self, ref): ''' Callback called by weakref when an object is about to be collected by garbage collector. ''' try: self._clients.remove(ref) except KeyError: pass # # Public methods: # Loading @@ -72,7 +82,10 @@ class RpcServer(object): :param conn: the connection to register. ''' self._clients.add(conn) self._clients.add(weakref.ref(conn, self._clean_conn)) gc.collect() # Force a manual garbage collection to avoid memory leak # with RpcConnections. This is maybe not required but I # need to read docs about python's gc and circular refs. def unregister(self, conn, shutdown=False): ''' Loading @@ -85,7 +98,6 @@ class RpcServer(object): if conn in self._clients: if shutdown: conn.shutdown() self._clients.remove(conn) def run(self): ''' Loading