xoscar
xoscar copied to clipboard
[BUG] State is changing in Stateless actor
Describe the bug
Started playing with the library, please correct me if I'm wrong but state should not change in Stateless actor and following ideally should not work like that or at least should warn in runtime.
To Reproduce
To help us to reproduce this bug, please provide information below:
import asyncio
import xoscar as xo
import nest_asyncio
nest_asyncio.apply()
class Counter(xo.StatelessActor): # <-- intentional to check it there's at least a runtime warning!
count = 0
def inc(self):
self.count += 1
print(self.count)
async def main():
address = "localhost:9999"
await xo.create_actor_pool(address=address, n_process=1)
actor = await xo.create_actor(
Counter,
address=address,
uid="1",
)
tasks = [actor.inc() for _ in range(10)]
await asyncio.gather(*tasks)
await xo.destroy_actor(actor)
asyncio.run(main())
outputs
1
2
3
4
5
6
7
8
9
10
- Your Python version: 3.10
- The version of Xoscar you use: latest 0.1
- Versions of crucial packages, such as numpy, scipy and pandas
- Full stack of the error.
- Minimized code to reproduce the error.
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
Good try, let's check what's going on there.
The StatelessActor is not for the actor has no state changes.
-
Actor - All the methods are guarded by an
asyncio.locks.Lock. - StatelessActor - All the methods are called directly.
Sorry for the misunderstanding. We will fix this issue in the next release.