xoscar icon indicating copy to clipboard operation
xoscar copied to clipboard

[BUG] State is changing in Stateless actor

Open ehsanmok opened this issue 2 years ago • 2 comments

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
  1. Your Python version: 3.10
  2. The version of Xoscar you use: latest 0.1
  3. Versions of crucial packages, such as numpy, scipy and pandas
  4. Full stack of the error.
  5. 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.

ehsanmok avatar Aug 27 '23 22:08 ehsanmok

Good try, let's check what's going on there.

qinxuye avatar Aug 28 '23 04:08 qinxuye

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.

codingl2k1 avatar Aug 28 '23 05:08 codingl2k1