Cannot get actors to work with async / await
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- python
调研方向
从链接的 actor 文档中的 async/await actor 示例开始,针对本地 Client 运行完整的 Python 复现。将文档所述行为与 traceback 进行比较,然后验证 async actor 示例能够正常工作,并确认 Waiter 示例使用了正确的声明。
由索引模型根据 Issue 内容生成。
描述
I have been searching for an actor framework in Python with good asyncio integration and appear to have found it!! However, running the examples from the docs on using actors with async/await yields an error. The complete code I am trying to run (copied from the examples) follows:
import asyncio
from dask.distributed import Client
class Counter:
""" A simple class to manage an incrementing counter """
n = 0
def __init__(self):
self.n = 0
def increment(self):
self.n += 1
return self.n
def add(self, x):
self.n += x
return self.n
async def test_async(client: Client) -> None:
counter = await client.submit(Counter, actor=True)
await counter.increment()
n = await counter.n
print(f'n = {n}')
if __name__ == '__main__':
client = Client()
asyncio.run(test_async(client))
Here is the full text of the error:
Traceback (most recent call last):
File "D:\Users\charl\Documents\2_dask\dask_test.py", line 30, in <module>
asyncio.run(test_async(client))
File "C:\Users\charl\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\charl\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\charl\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 684, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "D:\Users\charl\Documents\2_dask\dask_test.py", line 21, in test_async
counter = await client.submit(Counter, actor=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\charl\Documents\2_dask\.venv\Lib\site-packages\distributed\client.py", line 620, in __await__
return self.result().__await__()
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Users\charl\Documents\2_dask\.venv\Lib\site-packages\distributed\actor.py", line 165, in __getattr__
attr = getattr(self._cls, key)
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Counter' has no attribute '__await__'. Did you mean: '__init__'?
2024-11-16 13:03:27,968 - distributed.scheduler - WARNING - Removing worker 'tcp://127.0.0.1:62438' caused the cluster to lose already computed task(s), which will be recomputed elsewhere: {'Counter-23599479-2f43-4126-92ac-58b1f172a47e'} (stimulus_id='handle-worker-cleanup-1731783807.9682791')
Also as a side note, this text from the example using async in an actor function appears to have a typo (should be class Waiter not def Waiter)
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 778
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dask/distributed 的其他 Issue
-
needs triage
难度 2/5 1-3 小时 新手友好度 72/100
dask/distributed#9366 ·
-
needs triage
难度 2/5 1-3 小时 新手友好度 84/100
dask/distributed#9353 ·
-
documentation
难度 1/5 1-3 小时 新手友好度 82/100
dask/distributed#8304 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
dask/distributed#4816 · 2 条评论 ·
-
documentation good first issue
难度 2/5 1-3 小时 新手友好度 74/100
dask/distributed#2378 · 2 条评论 ·
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
PedestrianDynamics/pyFDS-Evac#343 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
theskumar/python-dotenv#708 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 2 天内回复
-
Docs Timedelta
难度 2/5 1-3 小时 新手友好度 72/100
pandas-dev/pandas#69919 ·
维护者通常 1 天内回复
-
API documentation
难度 2/5 1-3 小时 新手友好度 72/100
zephyrproject-rtos/west#1009 · 2 条评论 ·
维护者通常 3 天内回复