SkillAgentSearch skills...

Cleveland

Simple asyncio-based actors.

Install / Use

/learn @biesnecker/Cleveland
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Cleveland

Simple asyncio-based actors.

Named after Carol Cleveland, the only significant female performer on Monty Python's Flying Circus.

Example Usage

from cleveland.actor import BaseActor
from cleveland.message import Message
import asyncio

# Define new message classes, and register handlers for them in your actors.
class StringMessage(Message): pass

# Define actors that respond to Message subclasses with custom behavior.
class PrintActor(BaseActor):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.register_handler(StringMessage,
                              self._string_message_handler)


    @asyncio.coroutine
    def _string_message_handler(self, message):
        print(message.payload)

@asyncio.coroutine
def say_hello():
    a = BaseActor()
    b = PrintActor()
    a.start()
    b.start()
    for _ in range(10):
        message = StringMessage('Hello world!')
        yield from asyncio.sleep(0.25)
        yield from a.tell(b, message)
    yield from a.stop()
    yield from b.stop()

asyncio.get_event_loop().run_until_complete(say_hello())
View on GitHub
GitHub Stars38
CategoryDevelopment
Updated1y ago
Forks8

Languages

Python

Security Score

75/100

Audited on Jun 22, 2024

No findings