<commit_before>from __future__ import absolute_import, division, print_function, unicode_literals

import select

from echomesh.base import Config
from echomesh.util import Log
from echomesh.util.thread import ThreadLoop

LOGGER = Log.logger(__name__)

BUFFER_SIZE = 1024
TIMEOUT = 2.0

class SelectLoop(ThreadLoop.ThreadLoop):
  def __init__(self, *sockets):
    super(SelectLoop, self).__init__(name='SelectLoop')
    self.sockets = dict((s.socket, s) for s in sockets)
    Config.add_client(self)

  def config_update(self, get):
    self.timeout = get('network', 'discovery', 'timeout')
    LOGGER.debug('timeout=%s', self.timeout)

  def single_loop(self):
    try:
      result = select.select(self.sockets.keys(), [], [], TIMEOUT)
    except Exception:
      self._remove_bad()
    else:
      for socket in result[0]:
        s = self.sockets.get(socket)
        if not s:
          LOGGER.error("Got an update for a socket we didn't recognize.")
        elif not s.receive():
          self.remove_socket(socket)

  def remove_socket(self, socket):
    s = self.sockets.get(socket)
    if s:
      del self.sockets[socket]<commit_msg>Continuing the change to timeouts.<commit_after>from __future__ import absolute_import, division, print_function, unicode_literals

import select

from echomesh.base import Config
from echomesh.expression import Expression
from echomesh.util import Log
from echomesh.util.thread import ThreadLoop

LOGGER = Log.logger(__name__)

BUFFER_SIZE = 1024
TIMEOUT = 2.0

class SelectLoop(ThreadLoop.ThreadLoop):
  def __init__(self, *sockets):
    super(SelectLoop, self).__init__(name='SelectLoop')
    self.sockets = dict((s.socket, s) for s in sockets)
    Config.add_client(self)

  def config_update(self, get):
    self.timeout = Expression.convert(get('network', 'timeout'))
    LOGGER.debug('timeout=%s', self.timeout)

  def single_loop(self):
    try:
      result = select.select(self.sockets.keys(), [], [], TIMEOUT)
    except Exception:
      self._remove_bad()
    else:
      for socket in result[0]:
        s = self.sockets.get(socket)
        if not s:
          LOGGER.error("Got an update for a socket we didn't recognize.")
        elif not s.receive():
          self.remove_socket(socket)

  def remove_socket(self, socket):
    s = self.sockets.get(socket)
    if s:
      del self.sockets[socket]
{'fraction_non_alphanumeric': 0.1120067882901994, 'fraction_numerical': 0.005939753924480272, 'mean_word_length': 3.578640776699029, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4030677', 'n_tokens_mistral': 754, 'n_tokens_neox': 727, 'n_words': 190}