2
我正在運行函數provision_ec2_node()
,通過默認的asyncio
事件循環thread executor。該函數需要一些參數,我通過functools.partial()
傳遞給執行者。從Python 3.5開始,BaseEventLoop.run_in_executor()拋出「意外的關鍵字參數'回調'」
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))
此代碼在Python 3.4上正常工作,我已經使用它幾個月。
不過,我最近升級到Python 3.5,現在上面的代碼引發此錯誤:
TypeError: run_in_executor() got an unexpected keyword argument 'callback'
在Python 3.5 release notes concerning asyncio
來看,我沒有看到任何這解釋行爲的這種變化。此外,3.5文檔still sayfunctools.partial()
是將關鍵字的函數傳遞給執行程序的正確方法。
什麼給?
尼斯漁獲物。我會稍微嘗試一下並回報。我知道'asyncio'在3.4中被標記爲暫時的,但是看起來奇怪的是它們會破壞參數名稱的向後兼容性。你會碰巧知道爲什麼會發生這種變化嗎?我假設這不是一個無聊的變化。 –
幾乎每個發行版AFAIK都打破了對'asyncio'的向後兼容性。它是實驗性的,API尚不穩定。關於爲什麼它被改變了......'asyncio'是在單獨的倉庫中開發的,並且被合併到主'cpython'倉庫中。根據源代碼提交,它是「[爲了避免混淆](https://github.com/python/asyncio/commit/2798fb43af22c966a0c7ba15258a073cf651a3c2)」。這是有道理的,因爲它是一個執行功能而不是回調。 –
我明白了。它看起來像下一個版本的Python 3.4(3.4.4?)將包括所有這些從3.5,每[3.5發佈說明](https://docs.python.org/3/whatsnew/3.5)的'asyncio'變化的.html#ASYNCIO)。所以當發生這種情況時,理論上可以兼容3.5+和3.4.4+。 –