autogen/samples/apps/cap/py/demo/SimpleActorDemo.py
Rajan db30ec8961
Reduce sleep() in CAP library code (#2189)
* 1) Removed most framework sleeps 2) refactored connection code

* pre-commit fixes

* pre-commit

* ignore protobuf files in pre-commit checks

* Fix duplicate actor registration

* refactor change

* Nicer printing of Actors

* 1) Report recv_multipart errors 4) Always send 4 parts

* AutoGen generate_reply expects to wait indefinitely for an answer.  CAP can wait a certain amount and give up.   In order to reconcile the two, AutoGenConnector is set to wait indefinitely.

* pre-commit formatting fixes

* pre-commit format changes

* don't check autogenerated proto py files
2024-04-02 07:49:07 +00:00

29 lines
859 B
Python

import time
from AppAgents import GreeterAgent
from autogencap.LocalActorNetwork import LocalActorNetwork
from autogencap.DebugLog import Error
def simple_actor_demo():
"""
Demonstrates the usage of the CAP platform by registering an actor, connecting to the actor,
sending a message, and performing cleanup operations.
"""
# CAP Platform
network = LocalActorNetwork()
# Register an actor
network.register(GreeterAgent())
# Tell actor to connect to other actors
network.connect()
# Get a channel to the actor
greeter_link = network.lookup_actor("Greeter")
if greeter_link:
# Send a message to the actor
greeter_link.send_txt_msg("Hello World!")
# Cleanup
greeter_link.close()
else:
Error("simple_actor_demo", "Could not find Greeter")
network.disconnect()