-1

I have no problem using concurrent.futures if all my processes are started from different functions. But if I want to call the same function with different parameters I can't seem to get the syntax right. This is what I got so far but it doesn't work:

tasks = ((serial_port_local, serial_options_local, serial_port_remote, serial_options_remote, "local"),
(serial_port_remote, serial_options_remote, serial_port_local, serial_options_local, "remote"))

for task in zip(tasks, executor.map(serial_cross_over, tasks)):
    print (task)

This is the error but I don't grok it:

TypeError: serial_cross_over() missing 4 required positional arguments: 'receive_serial_options', 'send_serial_port', 'send_serial_options', and 'source'

Actually I don't really grok why its complicated at all. Shouldn't I just be able to do:

executor.submit(some_function(parameter1))
executor.submit(some_function(parameter2))

But that doesn't work. The program hangs on the second submit. Why?

dpetican
  • 771
  • 1
  • 5
  • 12

1 Answers1

0

It seems that serial_cross_over takes 4 arguments (correct me if I'm wrong) and you do not provide them when .map so, maybe take a look at this answer: Pass multiple parameters to concurrent.futures.Executor.map?

tasks = ((serial_port_local, serial_options_local, serial_port_remote, serial_options_remote, "local"), (serial_port_remote, serial_options_remote, serial_port_local, serial_options_local, "remote"))

for task in zip(executor.map(lambda p: f(*p), tasks)):
    pass

As for why doesn't executor.submit work as expected, I cannot tell without further details. Have you tried like this?:

with ThreadPoolExecutor(max_workers=1) as executor:
    future = executor.submit(some_function, parameter1)
    print(future.result())
Community
  • 1
  • 1
mkaran
  • 2,528
  • 20
  • 23