Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
coldfix committed Aug 3, 2018
1 parent 4b7f530 commit 1a46c7d
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions rpyc/utils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,8 @@ class ThreadPoolServer(Server):
def __init__(self, *args, **kwargs):
'''Initializes a ThreadPoolServer. In particular, instantiate the thread pool.'''
# get the number of threads in the pool
self.nbthreads = 20
if 'nbThreads' in kwargs:
self.nbthreads = kwargs['nbThreads']
del kwargs['nbThreads']
# get the request batch size
self.request_batch_size = 10
if 'requestBatchSize' in kwargs:
self.request_batch_size = kwargs['requestBatchSize']
del kwargs['requestBatchSize']
self.nbthreads = kwargs.pop('nbThreads', 20)
self.request_batch_size = kwargs.pop('requestBatchSize', 10)
# init the parent
Server.__init__(self, *args, **kwargs)
# a queue of connections having something to process
Expand Down Expand Up @@ -476,11 +469,7 @@ def _authenticate_and_build_connection(self, sock):
# authenticate
if self.authenticator:
h, p = sock.getpeername()
try:
sock, credentials = self.authenticator(sock)
except AuthenticationError:
self.logger.warning("%s:%s failed to authenticate, rejecting connection", h, p)
return None
sock, credentials = self.authenticator(sock)
else:
credentials = None
# build a connection
Expand All @@ -496,16 +485,12 @@ def _accept_method(self, sock):
# authenticate and build connection object
conn = self._authenticate_and_build_connection(sock)
# put the connection in the active queue
if conn:
h, p = sock.getpeername()
fd = conn.fileno()
self.logger.debug("Created connection to %s:%d with fd %d", h, p, fd)
self.fd_to_conn[fd] = conn
self._add_inactive_connection(fd)
self.clients.clear()
else:
self.logger.warning("Failed to authenticate and build connection, closing %s:%d", h, p)
sock.close()
h, p = sock.getpeername()
fd = conn.fileno()
self.logger.debug("Created connection to %s:%d with fd %d", h, p, fd)
self.fd_to_conn[fd] = conn
self._add_inactive_connection(fd)
self.clients.clear()
except Exception:
h, p = sock.getpeername()
self.logger.exception("Failed to serve client for %s:%d, caught exception", h, p)
Expand Down

0 comments on commit 1a46c7d

Please sign in to comment.