def poll_connections(server):

    Logger.log("Server started")
    Logger.log(server.getsockname())
    connections = []

    while server_running:

        # Occasionally timeout from polling to check if the server is still running
        try:
            client, client_address = server.accept()
        except sock.timeout:
            continue

        Logger.log("Anonymous user connected from address: " +
                   client_address[0])
        new_session = Session((client, client_address))
        new_session.start()

        connections.append(new_session)

    for connection in connections:
        if connection.is_alive():
            connection.kill()

    server.shutdown(sock.SHUT_RDWR)
    server.close()
    Logger.log("Server stopped")
def poll_connections(server):

    Logger.log("Server started")
    Logger.log(server.getsockname())

    while server_running:

        # Occasionally timeout from polling to check if the server is still running
        try:
            client, client_address = server.accept()
        except sock.timeout:
            continue

        Logger.log("Anonymous user connected from address: " +
                   client_address[0])
        new_session = Session((client, client_address))
        new_session.start()

    Logger.log("Closing all sessions")
    for live_thread in threading.enumerate():
        if live_thread.name == 'session':
            live_thread.kill()

    active_count = threading.active_count()
    while active_count >= 4:

        update_count = threading.active_count()
        if active_count > update_count:

            active_count = update_count
            Logger.log("Sessions remaining: " + str(active_count - 3))

    Logger.log("*Safe to close server application*")

    server.shutdown(sock.SHUT_RDWR)
    server.close()
    Logger.log("Server stopped")