From e560322b9b9a14261c22d01d0e190a18457ef894 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 10 Mar 2019 15:56:20 -0400 Subject: [PATCH 1/2] Fix actor misnaming in 2nd spawning example Resolves #64 --- README.rst | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/README.rst b/README.rst index df6f223..cbbd456 100644 --- a/README.rst +++ b/README.rst @@ -159,7 +159,7 @@ Actor spawning and causality ``tractor`` tries to take ``trio``'s concept of causal task lifetimes to multi-process land. Accordingly, ``tractor``'s *actor nursery* behaves similar to ``trio``'s nursery_. That is, ``tractor.open_nursery()`` -opens an ``ActorNursery`` which waits on spawned *actors* to complete +opens an ``ActorNursery`` which **must** wait on spawned *actors* to complete (or error) in the same causal_ way ``trio`` waits on spawned subtasks. This includes errors from any one actor causing all other actors spawned by the same nursery to be cancelled_. @@ -172,22 +172,21 @@ and use the ``run_in_actor()`` method: import tractor - def cellar_door(): - return "Dang that's beautiful" + def cellar_door(): + return "Dang that's beautiful" - async def main(): - """The main ``tractor`` routine. - """ - async with tractor.open_nursery() as n: + async def main(): + """The main ``tractor`` routine. + """ + async with tractor.open_nursery() as n: - portal = await n.run_in_actor('teacher', cellar_door) + portal = await n.run_in_actor('some_linguist', cellar_door) - # The ``async with`` will unblock here since the 'frank' - # actor has completed its main task ``movie_theatre_question()``. - - print(await portal.result()) + # The ``async with`` will unblock here since the 'some_linguist' + # actor has completed its main task ``cellar_door``. + print(await portal.result()) tractor.run(main) @@ -204,11 +203,11 @@ What's going on? returned from ``nursery.run_in_actor()`` is used to communicate with the newly spawned *sub-actor* -- the second actor, *frank*, in a new *process* running a new ``trio`` task_ +- the second actor, *some_linguist*, in a new *process* running a new ``trio`` task_ then executes ``cellar_door()`` and returns its result over a *channel* back to the parent actor -- the parent actor retrieves the subactor's (*frank*) *final result* using ``portal.result()`` +- the parent actor retrieves the subactor's *final result* using ``portal.result()`` much like you'd expect from a future_. This ``run_in_actor()`` API should look very familiar to users of @@ -227,7 +226,7 @@ method: method and act like an RPC daemon that runs indefinitely (the ``with tractor.open_nursery()`` won't exit) until cancelled_ -Had we wanted the latter form in our example it would have looked like: +Here is a similar example using the latter method: .. code:: python From 322145684bd945b17561e908195f22e606ef6f22 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 10 Mar 2019 15:59:59 -0400 Subject: [PATCH 2/2] Pass an actor name to `main()` in discovery ex Resolves #41 --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index cbbd456..d31a2bb 100644 --- a/README.rst +++ b/README.rst @@ -581,7 +581,7 @@ find an actor's socket address by name use the ``find_actor()`` function: print(f"my_service is found at {my_service}") - tractor.run(main, service_name) + tractor.run(main, 'some_actor_name') The ``name`` value you should pass to ``find_actor()`` is the one you passed as the