def _compact(self, address_list, name):
        ctx = context.get_context()
        sock_log = ctx.log.get_logger('NET.SOCKET')
        all_pools = sum([e.values() for e in self.sockpools.values()], [])
        with ctx.log.get_logger('CULL').info(name) as _log:
            _log['len'] = len(all_pools)
            for pool in all_pools:
                pool.cull()

        total_num_in_use = sum([len(model.active_connections)
                                for model in self.server_models.values()])

        if total_num_in_use >= GLOBAL_MAX_CONNECTIONS:
            sock_log.critical('GLOBAL_MAX').success('culling sockets',
                                                    limit=GLOBAL_MAX_CONNECTIONS,
                                                    in_use=total_num_in_use)
            # try to cull sockets to make room
            made_room = False
            for pool in all_pools:
                if pool.total_sockets:
                    made_room = True
                    gevent.joinall(pool.reduce_size(pool.total_sockets / 2))
            if not made_room:
                ctx.intervals['net.out_of_sockets'].tick()
                raise OutOfSockets("maximum global socket limit {0} hit: {1}".format(
                    GLOBAL_MAX_CONNECTIONS, total_num_in_use))

        num_in_use = sum([len(self.server_models[address].active_connections)
                          for address in address_list])

        if num_in_use >= MAX_CONNECTIONS:
            sock_log.critical('ADDR_MAX').success('culling {addr} sockets',
                                                  limit=GLOBAL_MAX_CONNECTIONS,
                                                  in_use=total_num_in_use,
                                                  addr=repr(address_list))

            # try to cull sockets
            made_room = False
            for pool in all_pools:
                for address in address_list:
                    num_pooled = pool.socks_pooled_for_addr(address)
                    if num_pooled:
                        gevent.joinall(pool.reduce_addr_size(address, num_pooled / 2))
                        made_room = True
            if not made_room:
                ctx.intervals['net.out_of_sockets'].tick()
                ctx.intervals['net.out_of_sockets.' + str(name)].tick()
                raise OutOfSockets("maximum sockets for {0} already in use: {1}".format(
                    name, num_in_use))
        return
try to compact and make room for a new socket connection to one of
dataset/ETHPy150Open paypal/support/support/connection_mgr.py/ConnectionManager._compact