Skip to content

Commit

Permalink
Merge pull request #204 from xBeAsTx/logging_fix
Browse files Browse the repository at this point in the history
numed workers, logging exceptions fix
  • Loading branch information
coldfix authored May 29, 2017
2 parents eb3c7b8 + d56be5b commit 4ef652e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions rpyc/utils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,9 @@ def __init__(self, *args, **kwargs):
self.active = True
# setup the thread pool for handling requests
self.workers = []
for _ in range(nbthreads):
for i in range(nbthreads):
t = threading.Thread(target = self._serve_clients)
t.setName('ThreadPoolWorker')
t.setName('Worker%i' % i)
t.daemon = True
t.start()
self.workers.append(t)
Expand Down Expand Up @@ -352,16 +352,20 @@ def _remove_from_inactive_connection(self, fd):

def _drop_connection(self, fd):
'''removes a connection by closing it and removing it from internal structs'''
conn = None

# cleanup fd_to_conn dictionnary
try:
conn = self.fd_to_conn[fd]
del self.fd_to_conn[fd]
except KeyError:
# the active connection has already been removed
pass

# close connection
self.logger.info("Closing connection for fd %d", fd)
conn.close()
if conn:
conn.close()

def _add_inactive_connection(self, fd):
'''adds a connection to the set of inactive ones'''
Expand Down Expand Up @@ -439,9 +443,8 @@ def _serve_clients(self):
# thread can stop even if there is nothing in the queue
pass
except Exception:
ex = sys.exc_info()[1]
# "Caught exception in Worker thread" message
self.logger.warning("Failed to serve client, caught exception : %s", str(ex))
self.logger.exception("failed to serve client, caught exception")
# wait a bit so that we do not loop too fast in case of error
time.sleep(0.2)

Expand Down Expand Up @@ -483,8 +486,7 @@ def _accept_method(self, sock):
sock.close()
except Exception:
h, p = sock.getpeername()
ex = sys.exc_info()[1]
self.logger.warning("Failed to serve client for %s:%d, caught exception : %s", h, p, str(ex))
self.logger.exception("Failed to serve client for %s:%d, caught exception", h, p)
sock.close()


Expand Down

0 comments on commit 4ef652e

Please sign in to comment.