Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop run #197

Merged
merged 15 commits into from
May 7, 2021
Merged
23 changes: 17 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ and use the ``run_in_actor()`` method:

What's going on?

- an initial *actor* is started with ``tractor.run()`` and told to execute
- an initial *actor* is started with ``trio.run()`` and told to execute
its main task_: ``main()``

- inside ``main()`` an actor is *spawned* using an ``ActorNusery`` and is told
Expand Down Expand Up @@ -182,7 +182,7 @@ Here is a similar example using the latter method:

.. literalinclude:: ../examples/actor_spawning_and_causality_with_daemon.py

The ``rpc_module_paths`` `kwarg` above is a list of module path
The ``enable_modules`` `kwarg` above is a list of module path
strings that will be loaded and made accessible for execution in the
remote actor through a call to ``Portal.run()``. For now this is
a simple mechanism to restrict the functionality of the remote
Expand Down Expand Up @@ -458,7 +458,7 @@ find an actor's socket address by name use the ``find_actor()`` function:
.. literalinclude:: ../examples/service_discovery.py

The ``name`` value you should pass to ``find_actor()`` is the one you passed as the
*first* argument to either ``tractor.run()`` or ``ActorNursery.start_actor()``.
*first* argument to either ``trio.run()`` or ``ActorNursery.start_actor()``.


Running actors standalone
Expand All @@ -472,15 +472,25 @@ need to hop into a debugger. You just need to pass the existing

.. code:: python

tractor.run(main, arbiter_addr=('192.168.0.10', 1616))
import trio
import tractor

async def main():

async with tractor.open_root_actor(
arbiter_addr=('192.168.0.10', 1616)
):
await trio.sleep_forever()

trio.run(main)


Choosing a process spawning backend
***********************************
``tractor`` is architected to support multiple actor (sub-process)
spawning backends. Specific defaults are chosen based on your system
but you can also explicitly select a backend of choice at startup
via a ``start_method`` kwarg to ``tractor.run()``.
via a ``start_method`` kwarg to ``tractor.open_nursery()``.

Currently the options available are:

Expand Down Expand Up @@ -536,13 +546,14 @@ main python module of the program:
.. code:: python

# application/__main__.py
import trio
import tractor
import multiprocessing
from . import tractor_app

if __name__ == '__main__':
multiprocessing.freeze_support()
tractor.run(tractor_app.main)
trio.run(tractor_app.main)

And execute as::

Expand Down
2 changes: 1 addition & 1 deletion examples/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# temporary dir and name it test_example.py. We import that script
# module here and invoke it's ``main()``.
from . import test_example
test_example.tractor.run(test_example.main, start_method='spawn')
test_example.trio.run(test_example.main)
3 changes: 2 additions & 1 deletion examples/a_trynamic_first_scene.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import trio
import tractor

_this_module = __name__
Expand Down Expand Up @@ -40,4 +41,4 @@ async def main():


if __name__ == '__main__':
tractor.run(main)
trio.run(main)
3 changes: 2 additions & 1 deletion examples/actor_spawning_and_causality.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import trio
import tractor


Expand All @@ -23,4 +24,4 @@ async def main():


if __name__ == '__main__':
tractor.run(main)
trio.run(main)
5 changes: 3 additions & 2 deletions examples/actor_spawning_and_causality_with_daemon.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import trio
import tractor


Expand All @@ -16,7 +17,7 @@ async def main():
portal = await n.start_actor(
'frank',
# enable the actor to run funcs from this current module
rpc_module_paths=[__name__],
enable_modules=[__name__],
)

print(await portal.run(movie_theatre_question))
Expand All @@ -30,4 +31,4 @@ async def main():


if __name__ == '__main__':
tractor.run(main)
trio.run(main)
9 changes: 6 additions & 3 deletions examples/asynchronous_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ async def stream_forever():


async def main():

# stream for at most 1 seconds
with trio.move_on_after(1) as cancel_scope:

async with tractor.open_nursery() as n:

portal = await n.start_actor(
f'donny',
rpc_module_paths=[__name__],
'donny',
enable_modules=[__name__],
)

# this async for loop streams values from the above
Expand All @@ -34,4 +37,4 @@ async def main():


if __name__ == '__main__':
tractor.run(main)
trio.run(main)
2 changes: 1 addition & 1 deletion examples/debugging/multi_daemon_subactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def breakpoint_forever():

async def name_error():
"Raise a ``NameError``"
getattr(doggypants)
getattr(doggypants) # noqa


async def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

async def name_error():
"Raise a ``NameError``"
getattr(doggypants)
getattr(doggypants) # noqa


async def breakpoint_forever():
Expand Down
9 changes: 6 additions & 3 deletions examples/debugging/multi_subactor_root_errors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import trio
import tractor


async def name_error():
"Raise a ``NameError``"
getattr(doggypants)
getattr(doggypants) # noqa


async def spawn_error():
Expand Down Expand Up @@ -32,7 +33,9 @@ async def main():
- root actor should then fail on assert
- program termination
"""
async with tractor.open_nursery() as n:
async with tractor.open_nursery(
debug_mode=True,
) as n:

# spawn both actors
portal = await n.run_in_actor(
Expand All @@ -54,4 +57,4 @@ async def main():


if __name__ == '__main__':
tractor.run(main, debug_mode=True)
trio.run(main)
8 changes: 5 additions & 3 deletions examples/debugging/multi_subactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async def breakpoint_forever():

async def name_error():
"Raise a ``NameError``"
getattr(doggypants)
getattr(doggypants) # noqa


async def spawn_error():
Expand All @@ -36,7 +36,9 @@ async def main():
`-python -m tractor._child --uid ('spawn_error', '52ee14a5 ...)
`-python -m tractor._child --uid ('name_error', '3391222c ...)
"""
async with tractor.open_nursery() as n:
async with tractor.open_nursery(
debug_mode=True,
) as n:

# Spawn both actors, don't bother with collecting results
# (would result in a different debugger outcome due to parent's
Expand All @@ -47,4 +49,4 @@ async def main():


if __name__ == '__main__':
tractor.run(main, debug_mode=True)
trio.run(main)
12 changes: 8 additions & 4 deletions examples/debugging/root_actor_breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

async def main():

await trio.sleep(0.1)
async with tractor.open_root_actor(
debug_mode=True,
):

await tractor.breakpoint()
await trio.sleep(0.1)

await trio.sleep(0.1)
await tractor.breakpoint()

await trio.sleep(0.1)


if __name__ == '__main__':
tractor.run(main, debug_mode=True)
trio.run(main)
10 changes: 7 additions & 3 deletions examples/debugging/root_actor_breakpoint_forever.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import trio
import tractor


async def main():

while True:
await tractor.breakpoint()
async with tractor.open_root_actor(
debug_mode=True,
):
while True:
await tractor.breakpoint()


if __name__ == '__main__':
tractor.run(main, debug_mode=True)
trio.run(main)
8 changes: 6 additions & 2 deletions examples/debugging/root_actor_error.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import trio
import tractor


async def main():
assert 0
async with tractor.open_root_actor(
debug_mode=True,
):
assert 0


if __name__ == '__main__':
tractor.run(main, debug_mode=True)
trio.run(main)
10 changes: 7 additions & 3 deletions examples/debugging/root_cancelled_but_child_is_in_tty_lock.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import trio
import tractor


async def name_error():
"Raise a ``NameError``"
getattr(doggypants)
getattr(doggypants) # noqa


async def spawn_until(depth=0):
Expand Down Expand Up @@ -37,7 +38,10 @@ async def main():
└─ python -m tractor._child --uid ('name_error', '6c2733b8 ...)

"""
async with tractor.open_nursery() as n:
async with tractor.open_nursery(
debug_mode=True,
loglevel='warning'
) as n:

# spawn both actors
portal = await n.run_in_actor(
Expand All @@ -58,4 +62,4 @@ async def main():


if __name__ == '__main__':
tractor.run(main, debug_mode=True, loglevel='warning')
trio.run(main)
6 changes: 4 additions & 2 deletions examples/debugging/subactor_breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ async def breakpoint_forever():

async def main():

async with tractor.open_nursery() as n:
async with tractor.open_nursery(
debug_mode=True,
) as n:

portal = await n.run_in_actor(
breakpoint_forever,
Expand All @@ -21,4 +23,4 @@ async def main():


if __name__ == '__main__':
tractor.run(main, debug_mode=True, loglevel='debug')
trio.run(main)
7 changes: 5 additions & 2 deletions examples/debugging/subactor_error.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import trio
import tractor


Expand All @@ -6,11 +7,13 @@ async def name_error():


async def main():
async with tractor.open_nursery() as n:
async with tractor.open_nursery(
debug_mode=True,
) as n:

portal = await n.run_in_actor(name_error)
await portal.result()


if __name__ == '__main__':
tractor.run(main, debug_mode=True)
trio.run(main)
7 changes: 4 additions & 3 deletions examples/full_fledged_streaming_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ async def push_to_chan(portal, send_chan):
# this is the main actor and *arbiter*
async def main():
# a nursery which spawns "actors"
async with tractor.open_nursery() as nursery:
async with tractor.open_nursery(
arbiter_addr=('127.0.0.1', 1616)
) as nursery:

seed = int(1e3)
import time
pre_start = time.time()

portal = await nursery.start_actor(
Expand Down Expand Up @@ -100,4 +101,4 @@ async def main():


if __name__ == '__main__':
final_stream = tractor.run(main, arbiter_addr=('127.0.0.1', 1616))
final_stream = trio.run(main)
3 changes: 3 additions & 0 deletions examples/parallelism/_concurrent_futures_primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
115797848077099,
1099726899285419]


def is_prime(n):
if n < 2:
return False
Expand All @@ -24,6 +25,7 @@ def is_prime(n):
return False
return True


def main():
with concurrent.futures.ProcessPoolExecutor() as executor:
start = time.time()
Expand All @@ -33,6 +35,7 @@ def main():

print(f'processing took {time.time() - start} seconds')


if __name__ == '__main__':

start = time.time()
Expand Down
2 changes: 1 addition & 1 deletion examples/parallelism/concurrent_actors_primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor-example

This uses no extra threads, fancy semaphores or futures; all we need
This uses no extra threads, fancy semaphores or futures; all we need
is ``tractor``'s channels.

"""
Expand Down
Loading