def mp_worker(item):
    return item, count

def mp_handler():
    cpus = multiprocessing.cpu_count()
p = multiprocessing.Pool(cpus)
with open('ExampleFile.txt') as f:
    listX = [line for line in (l.strip() for l in f) if line]
with open('results.txt', 'w') as f:
    for result in p.imap(mp_worker, listX):
        f.write('%s: %d\n' % result)
if __name__ == '__main__':
    mp_handler()
Writing to a file with multiprocessing