Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BaseEventLoop.run_in_executor() throws "unexpected keyword argument 'callback'" starting in Python 3.5

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?

like image 645
Nick Chammas Avatar asked Dec 12 '25 02:12

Nick Chammas


1 Answers

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(...))
like image 177
Yaroslav Admin Avatar answered Dec 15 '25 15:12

Yaroslav Admin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!