Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numed workers, logging exceptions fix #204

Merged
merged 2 commits into from
May 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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