<commit_before>#!/usr/bin/env python

import socket
import signal

globalServerList = []

#Poll each server if they are still running. Get the amount of players from the server as response
def pollServerList(serverList):
  addr = ""
  port = int()
  response = ""
  newlist = []
  for server in serverList:
    addr = server[0].split(' ')[0]
    port = int(server[0].split(' ')[1])
    try:
      sock = socket.create_connection((addr, port), 1)
    except socket.error:
      print "Following server is no longer running: %s %s" % (addr, str(port))
      continue
    sock.send("P")
    #Get the number of players as response
    response = sock.recv(1024)
    if not response[0] == 'R':
      print "Server returned unexpected response"
      continue
    server[2] = response[1]
    newlist.append(server)
    sock.close()
  return newlist

#Signal handler. Terminate every map server before quitting
def killServerList(signal, frame):
  print "Received system signal. Will kill all map server, then exit."
  addr = ""
  port = int()
  response = ""
  newlist = []<commit_msg>Handled timeout for disconnected servers<commit_after>#!/usr/bin/env python

import socket
import signal

globalServerList = []

#Poll each server if they are still running. Get the amount of players from the server as response
def pollServerList(serverList):
  addr = ""
  port = int()
  response = ""
  newlist = []
  for server in serverList:
    addr = server[0].split(' ')[0]
    port = int(server[0].split(' ')[1])
    try:
      sock = socket.create_connection((addr, port), 1)
    except socket.error:
      print "Following server is no longer running: %s %s" % (addr, str(port))
      continue
    sock.send("P")
    #Get the number of players as response
    try:
      response = sock.recv(1024)
    except socket.timeout:
      print "Socket timeout with: %s %s" % (addr, str(port))
      continue
    if not response[0] == 'R':
      print "Server returned unexpected response"
      continue
    server[2] = response[1]
    newlist.append(server)
    sock.close()
  return newlist

#Signal handler. Terminate every map server before quitting
def killServerList(signal, frame):
  print "Received system signal. Will kill all map server, then exit."
  addr = ""
  port = int()
  response = ""
  newlist = []
{'fraction_non_alphanumeric': 0.11570247933884298, 'fraction_numerical': 0.010439321444106133, 'mean_word_length': 3.2357274401473295, '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': '6405711', 'n_tokens_mistral': 698, 'n_tokens_neox': 684, 'n_words': 244}