I am running a function, provision_ec2_node(), via the default asyncio event loop thread executor. The function takes a number of arguments which I pass to the executor via functools.partial().
task = loop.run_in_executor(
executor=None,
callback=functools.partial(
provision_ec2_node,
modules=modules,
host=instance.ip_address,
identity_file=identity_file,
cluster_info=cluster_info))
This code works fine on Python 3.4, and I've been using it like this for several months.
However, I recently upgraded to Python 3.5, and now the above code throws this error:
TypeError: run_in_executor() got an unexpected keyword argument 'callback'
Looking at the Python 3.5 release notes concerning asyncio, I don't see anything which explains this change of behavior. Furthermore, the 3.5 docs still say that functools.partial() is the correct way to pass a function with keywords to an executor.
What gives?
Apparently the second parameter was renamed from callback to func, but the change was not reflected in the docs change is reflected in the docs as of 2015-10-01. That's why it fails.
Either update it to the new name (and lose Python <3.5 compatibility) or pass the parameters as positional ones:
task = loop.run_in_executor(None, functools.partial(...))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With