From 2f8dd0199d07f1727df1ce3db76c35a50702d056 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 25 Feb 2021 23:51:53 -0500 Subject: [PATCH 1/4] Tweak version for release, add 3.9 tag --- setup.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 20e748d..cf3e838 100755 --- a/setup.py +++ b/setup.py @@ -24,8 +24,8 @@ with open('docs/README.rst', encoding='utf-8') as f: setup( name="tractor", - version='0.1.0.alpha0', - description='A trionic actor model built on `multiprocessing` and `trio`', + version='0.1.0a0.dev0', # first ever alpha, dev release + description='structured concurrrent "actors"', long_description=readme, license='GPLv3', author='Tyler Goodlet', @@ -38,14 +38,23 @@ setup( 'tractor.testing', ], install_requires=[ - 'msgpack', 'trio>0.8', 'async_generator', 'colorlog', 'wrapt', - 'trio_typing', 'pdbpp', + 'trio>0.8', + 'msgpack', + 'async_generator', + 'colorlog', + 'wrapt', + 'trio_typing', + 'pdbpp', ], tests_require=['pytest'], python_requires=">=3.7", keywords=[ - "async", "concurrency", "actor model", "distributed", - 'trio', 'multiprocessing' + 'trio', + "async", + "concurrency", + "actor model", + "distributed", + 'multiprocessing' ], classifiers=[ 'Development Status :: 3 - Alpha', @@ -57,6 +66,7 @@ setup( "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Intended Audience :: Science/Research", "Intended Audience :: Developers", "Topic :: System :: Distributed Computing", From 3766731de55556b25314d324ea8a53476f227edc Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 27 Feb 2021 14:21:27 -0500 Subject: [PATCH 2/4] Add a single func ex for our first one --- docs/README.rst | 59 +++++++++++++++++++++++++++++ examples/parallelism/single_func.py | 43 +++++++++++++++++++++ setup.py | 2 +- 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 examples/parallelism/single_func.py diff --git a/docs/README.rst b/docs/README.rst index ed19b83..2a5e42b 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -31,6 +31,64 @@ Features communications protocols, and environment specific IPC primitives +Run a func in a process +----------------------- +Use ``trio``'s style of focussing on *tasks as functions*: + +.. code:: python + + """ + Run with a process monitor from a terminal using:: + + $TERM -e watch -n 0.1 "pstree -a $$" \ + & python examples/parallelism/single_func.py \ + && kill $! + + """ + import os + + import tractor + import trio + + + async def burn_cpu(): + + pid = os.getpid() + + # burn a core @ ~ 50kHz + for _ in range(50000): + await trio.sleep(1/50000/50) + + return os.getpid() + + + async def main(): + + async with tractor.open_nursery() as n: + + portal = await n.run_in_actor(burn_cpu) + + # burn rubber in the parent too + await burn_cpu() + + # wait on result from target function + pid = await portal.result() + + # end of nursery block + print(f"Collected subproc {pid}") + + + if __name__ == '__main__': + trio.run(main) + + +This runs ``burn_cpu()`` in a new process and reaps it on completion +of the nursery block. + +If you only need to run a sync function and retreive a single result, you +might want to check out `trio-parallel`_. + + Zombie safe: self-destruct a process tree ----------------------------------------- ``tractor`` tries to protect you from zombies, no matter what. @@ -228,6 +286,7 @@ channel`_! .. _3 axioms: https://en.wikipedia.org/wiki/Actor_model#Fundamental_concepts .. _unrequirements: https://en.wikipedia.org/wiki/Actor_model#Direct_communication_and_asynchrony .. _async generators: https://www.python.org/dev/peps/pep-0525/ +.. _trio-parallel: https://github.com/richardsheridan/trio-parallel .. |gh_actions| image:: https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fgoodboy%2Ftractor%2Fbadge&style=popout-square diff --git a/examples/parallelism/single_func.py b/examples/parallelism/single_func.py new file mode 100644 index 0000000..8118b02 --- /dev/null +++ b/examples/parallelism/single_func.py @@ -0,0 +1,43 @@ +""" +Run with a process monitor from a terminal using:: + + $TERM -e watch -n 0.1 "pstree -a $$" \ + & python examples/parallelism/single_func.py \ + && kill $! + +""" +import os + +import tractor +import trio + + +async def burn_cpu(): + + pid = os.getpid() + + # burn a core @ ~ 50kHz + for _ in range(50000): + await trio.sleep(1/50000/50) + + return os.getpid() + + +async def main(): + + async with tractor.open_nursery() as n: + + portal = await n.run_in_actor(burn_cpu) + + # burn rubber in the parent too + await burn_cpu() + + # wait on result from target function + pid = await portal.result() + + # end of nursery block + print(f"Collected subproc {pid}") + + +if __name__ == '__main__': + trio.run(main) diff --git a/setup.py b/setup.py index cf3e838..4ed3b5f 100755 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ with open('docs/README.rst', encoding='utf-8') as f: setup( name="tractor", - version='0.1.0a0.dev0', # first ever alpha, dev release + version='0.1.0a0', # first ever alpha description='structured concurrrent "actors"', long_description=readme, license='GPLv3', From c07a5f6e11cc0169639b1284823bed5ec2c2128d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 27 Feb 2021 16:08:44 -0500 Subject: [PATCH 3/4] Try fix worker pool link, again --- docs/README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/README.rst b/docs/README.rst index 2a5e42b..6ad8f1d 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -208,7 +208,7 @@ pool thing?"*. tree you can imagine; a "worker pool" pattern is a trivial special case. -We have a `full re-implementation `_ of the std-lib's +We have a `full worker pool re-implementation`_ of the std-lib's ``concurrent.futures.ProcessPoolExecutor`` example for reference. You can run it like so (from this dir) to see the process tree in @@ -222,7 +222,7 @@ This uses no extra threads, fancy semaphores or futures; all we need is ``tractor``'s IPC! -.. _worker_pool: https://github.com/goodboy/tractor/blob/master/examples/parallelism/concurrent_actors_primes.py +.. _full worker pool re-implementation: https://github.com/goodboy/tractor/blob/master/examples/parallelism/concurrent_actors_primes.py Install ------- From e80ab60e0bf099a4274079a2fc9c3053ad94affc Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 27 Feb 2021 16:10:57 -0500 Subject: [PATCH 4/4] Add pypi install line --- docs/README.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/README.rst b/docs/README.rst index 6ad8f1d..27b4d40 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -226,7 +226,10 @@ is ``tractor``'s IPC! Install ------- -No PyPi release yet! +From PyPi:: + + pip install tractor + From git::