Skip to content
Open
1 change: 0 additions & 1 deletion python/xoscar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
file_object_ref,
copy_to,
Actor,
StatelessActor,
create_actor_pool,
setup_cluster,
wait_actor_pool_recovered,
Expand Down
11 changes: 5 additions & 6 deletions python/xoscar/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import annotations

import asyncio
from collections import defaultdict
from numbers import Number
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Type, Union
Expand All @@ -23,7 +24,7 @@
from .aio import AioFileObject
from .backend import get_backend
from .context import get_context
from .core import ActorRef, BufferRef, FileObjectRef, _Actor, _StatelessActor
from .core import ActorRef, BufferRef, FileObjectRef, _Actor

if TYPE_CHECKING:
from .backends.config import ActorPoolConfig
Expand Down Expand Up @@ -307,11 +308,9 @@ async def __on_receive__(self, message: Tuple[Any]):


class Actor(AsyncActorMixin, _Actor):
pass


class StatelessActor(AsyncActorMixin, _StatelessActor):
pass
# Guard all the methods with an instance of __xoscar_lock_type__
# Lock free if the __xoscar_lock_type__ is None.
__xoscar_lock_type__: Optional[type[asyncio.locks.Lock]] = asyncio.locks.Lock


_actor_implementation: Dict[Type[Actor], Type[Actor]] = dict()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ def echo(self, message):
return message


class ResourceLockActor(mo.StatelessActor):
class ResourceLockActor(mo.Actor):
__xoscar_lock_type__ = None

def __init__(self, count=1):
self._sem = asyncio.Semaphore(count)
self._requests = deque()
Expand Down
15 changes: 5 additions & 10 deletions python/xoscar/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,6 @@ cdef class _BaseActor:
raise ex


# The @cython.binding(True) is for ray getting members.
# The value is True by default after cython >= 3.0.0
@cython.binding(True)
cdef class _Actor(_BaseActor):
def _create_lock(self):
return asyncio.locks.Lock()


cdef class _FakeLock:
async def __aenter__(self):
pass
Expand All @@ -577,9 +569,12 @@ cdef class _FakeLock:
# The @cython.binding(True) is for ray getting members.
# The value is True by default after cython >= 3.0.0
@cython.binding(True)
cdef class _StatelessActor(_BaseActor):
cdef class _Actor(_BaseActor):
def _create_lock(self):
return _FakeLock()
lock_type = self.__xoscar_lock_type__
if lock_type is None:
return _FakeLock()
return lock_type()


cdef class BufferRef:
Expand Down