2021-02-24 18:39:14 +00:00
|
|
|
import trio
|
2020-02-09 07:01:39 +00:00
|
|
|
import tractor
|
|
|
|
|
|
|
|
|
2021-04-27 13:14:08 +00:00
|
|
|
async def cellar_door():
|
2020-12-21 14:09:55 +00:00
|
|
|
assert not tractor.is_root_process()
|
|
|
|
return "Dang that's beautiful"
|
2020-02-09 07:01:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
"""The main ``tractor`` routine.
|
|
|
|
"""
|
|
|
|
async with tractor.open_nursery() as n:
|
|
|
|
|
2020-12-21 14:09:55 +00:00
|
|
|
portal = await n.run_in_actor(
|
|
|
|
cellar_door,
|
|
|
|
name='some_linguist',
|
|
|
|
)
|
2020-02-09 07:01:39 +00:00
|
|
|
|
|
|
|
# The ``async with`` will unblock here since the 'some_linguist'
|
|
|
|
# actor has completed its main task ``cellar_door``.
|
|
|
|
|
|
|
|
print(await portal.result())
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-02-24 18:39:14 +00:00
|
|
|
trio.run(main)
|