import os
from glob import iglob
from concurrent.futures import ThreadPoolExecutor


def count_words_file(path):
    if not os.path.isfile(path):
        return 0
    with open(path) as file:
        return sum(len(line.split()) for line in file)


def count_words_sequential(pattern):
    return sum(map(count_words_file, iglob(pattern)))


def count_words_threading(pattern):
    with ThreadPoolExecutor() as pool:
        return sum(pool.map(count_words_file, iglob(pattern)))

[((124, 144), 'os.path.isfile', 'os.path.isfile', (['path'], {}), '(path)\n', (138, 144), False, 'import os\n'), ((387, 407), 'concurrent.futures.ThreadPoolExecutor', 'ThreadPoolExecutor', ([], {}), '()\n', (405, 407), False, 'from concurrent.futures import ThreadPoolExecutor\n'), ((323, 337), 'glob.iglob', 'iglob', (['pattern'], {}), '(pattern)\n', (328, 337), False, 'from glob import iglob\n'), ((463, 477), 'glob.iglob', 'iglob', (['pattern'], {}), '(pattern)\n', (468, 477), False, 'from glob import iglob\n')]