From fd679e5190eda8439c574e4495ef4613a79a88c0 Mon Sep 17 00:00:00 2001 From: Markus Grimm Date: Tue, 9 Aug 2016 12:07:04 +0200 Subject: [PATCH] Rewrote the check for closed connections. The crucial part is now guarded but the lock is only acquired when connection list needs to be modified. This avoids unnecessary locking. --- clients/rospy/src/rospy/topics.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/clients/rospy/src/rospy/topics.py b/clients/rospy/src/rospy/topics.py index c05983272a..b61a4ecadc 100644 --- a/clients/rospy/src/rospy/topics.py +++ b/clients/rospy/src/rospy/topics.py @@ -459,19 +459,15 @@ def cleanup_cb_wrapper(s): return True def check(self): - new_connections = self.connections[:] - removed_connection = False - - for fd in self.connection_poll.error_iter(): - to_remove = [x for x in new_connections if x.fileno() == fd] - - for x in to_remove: - removed_connection = True - rospydebug("removing connection to %s, connection error detected"%(x.endpoint_id)) - self._remove_connection(new_connections, x) - - if removed_connection: - self.connections = new_connections + fds_to_remove = list(self.connection_poll.error_iter()) + if fds_to_remove: + with self.c_lock: + new_connections = self.connections[:] + to_remove = [x for x in new_connections if x.fileno() in fds_to_remove] + for x in to_remove: + rospydebug("removing connection to %s, connection error detected"%(x.endpoint_id)) + self._remove_connection(new_connections, x) + self.connections = new_connections def remove_connection(self, c): """