Skip to content

[BUG] State is changing in Stateless actor #67

@ehsanmok

Description

@ehsanmok

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions