In pure Python (threads co-exist but not parallel), all threads can be waited to be all done by using join
method:
ts = [] # Threads
for i in range(10):
ts.append(Thread(func=...))
ts[-1].start()
for i in range(len(ts)):
ts[i].join() # Main thread waits for all these
In Cython, threads are created using prange
:
for i in prange(len(data), nogil=True, num_threads=10):
# Do something with data[i] in an uncertain thread id
pass
# Main thread back here
cython.parallel.join_all_prange_threads() # Need something like this
do_something_with_results_by_prange_threads()
Cython parallel module has prange
, parallel
, threadid
but no join
. Any way to wait for all threads in prange to be done first, in main thread? Since the code after depend on the results of prange threads.