2021-02-24 18:39:14 +00:00
|
|
|
import trio
|
2020-01-31 22:06:26 +00:00
|
|
|
import tractor
|
|
|
|
|
|
|
|
|
|
_this_module = __name__
|
|
|
|
|
the_line = 'Hi my name is {}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tractor.log.get_console_log("INFO")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def hi():
|
|
|
|
|
return the_line.format(tractor.current_actor().name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def say_hello(other_actor):
|
|
|
|
|
async with tractor.wait_for_actor(other_actor) as portal:
|
2020-12-21 14:09:55 +00:00
|
|
|
return await portal.run(hi)
|
2020-01-31 22:06:26 +00:00
|
|
|
|
|
|
|
|
|
2026-07-06 16:11:39 +00:00
|
|
|
async def run_and_print(
|
|
|
|
|
an: tractor.ActorNursery,
|
|
|
|
|
name: str,
|
|
|
|
|
other_actor: str,
|
|
|
|
|
):
|
|
|
|
|
print(
|
|
|
|
|
await tractor.to_actor.run(
|
|
|
|
|
say_hello,
|
|
|
|
|
an=an,
|
|
|
|
|
name=name,
|
|
|
|
|
# arguments are always named
|
|
|
|
|
other_actor=other_actor,
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-01-31 22:06:26 +00:00
|
|
|
async def main():
|
|
|
|
|
"""Main tractor entry point, the "master" process (for now
|
|
|
|
|
acts as the "director").
|
|
|
|
|
"""
|
2026-07-06 16:11:39 +00:00
|
|
|
async with (
|
|
|
|
|
tractor.open_nursery() as an,
|
|
|
|
|
trio.open_nursery() as tn,
|
|
|
|
|
):
|
2020-01-31 22:06:26 +00:00
|
|
|
print("Alright... Action!")
|
|
|
|
|
|
2026-07-06 16:11:39 +00:00
|
|
|
# both actors wait on the *other* to register so their
|
|
|
|
|
# one-shots must run concurrently.
|
|
|
|
|
tn.start_soon(run_and_print, an, 'donny', 'gretchen')
|
|
|
|
|
tn.start_soon(run_and_print, an, 'gretchen', 'donny')
|
|
|
|
|
|
|
|
|
|
print("CUTTTT CUUTT CUT!!! Donny!! You're supposed to say...")
|
2020-01-31 22:06:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-02-24 18:39:14 +00:00
|
|
|
trio.run(main)
|