+5 votes
in Programming Languages by (72.7k points)

The following code is throwing the error: "SyntaxError: Generator expression must be parenthesized if not sole argument"

import concurrent.futures as cf

with cf.ProcessPoolExecutor(max_workers=n_threads) as executor:

    write_status = [executor.submit(write_data_to_outfile, ofile, records[rc*j: rc*(j+1)] for j in range(n_threads))]

What is wrong with this code?

1 Answer

+1 vote
by (354k points)
selected by
 
Best answer

You have placed an extra ")" after n_threads. You are also missing ")" before "for". Fix them and the code should work.

From

write_status = [executor.submit(write_data_to_outfile, ofile, records[rc*j: rc*(j+1)] for j in range(n_threads))]

to

write_status = [executor.submit(write_data_to_outfile, ofile, records[rc*j: rc*(j+1)]) for j in range(n_threads)]


...