Q:

Python: parallelizing any/all statements

I am running some Python program and I've noticed that the bottleneck is in the line doing the following 
all(foo(s) for s in l)

what I am wondering is - what would be the best way to make this into a parallel computation? foo(s) is a thread safe method inspecting s and returning True/False with respect to some criteria. No data structure is changed by foo.
So the question is

How to test in parallel if all elements of a list l have property foo
  , exiting as soon as one element of l does not satisfy foo?

Edit. Adding more context. I do not know what kind of context you are looking for but in my scenario s is a graph and foo(s) computes some graph theoretical invariant (for example average distance or perhaps something similar)

A:

This will sort of depend on what foo(s) is doing.  If it is I/O bound, waiting on blocking calls, than just using threads will help.  The easiest way is to create a pool of threads and use pool.map:
from multiprocessing.pool import ThreadPool
pool = ThreadPool(10)
all(pool.map(foo, l))

If, however, the function is cpu bound, using a lot of processor power, this will not help you.  Instead you need to use the multiprocessing pool: 
from multiprocessing import Pool
pool = Pool(4)
all(pool.map(foo, l))

This will use separate processes instead of threads, allowing multiple cpu cores to be used.  If your function foo is very quick, though, the overhead will eliminate any advantage of parallel processing, so you need to test to make sure you get the results you expect
see: https://docs.python.org/2/library/multiprocessing.html#using-a-pool-of-workers
EDIT:
I've assumed you're using Python 2.7.x.  If you're using Python3 you have more advanced concurrency features in concurrent.futures.  Including ThreadPoolExecutor and ProcessPoolExecutor.  
I would recommend using those for parallel processing and the asyncio lib for I/O bound problems.

