+5 votes
in Programming Languages by (71.8k 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 (349k 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)]


...