Issue
I am trying to pass arguments to run_in_executor
like so:
loop.run_in_executor(None, update_contacts, data={
'email': email,
'access_token': g.tokens['access_token']
})
However, I get the following error:
run_in_executor() got an unexpected keyword argument 'data'
Is there a generic way to pass args to this function?
Solution
Use functools.partial
; it's a standard way to do such things, and it's specifically recommended in the docs for loop.run_in_executor
, as well as more generally in the Event Loop docs.
Here's how it might look for you:
import functools # at the top with the other imports
loop.run_in_executor(None, functools.partial(update_contacts, data={
'email': email,
'access_token': g.tokens['access_token']
}))
You could also do from functools import partial
, if you like.
Answered By - Cyphase
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.