+4 votes
in Programming Languages by (17.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

0 votes
by (35.8k points)

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)]

...