def reset(self):
# Ignore this race condition -- if many threads are resetting at once,
# the pool_id will definitely change, which is all we care about.
self.pool_id += 1
self.pid = os.getpid()
sockets = None
try:
# Swapping variables is not atomic. We need to ensure no other
# thread is modifying self.sockets, or replacing it, in this
# critical section.
self.lock.acquire()
sockets, self.sockets = self.sockets, set()
finally:
self.lock.release()
for sock_info in sockets:
sock_info.close()
评论列表
文章目录