Skip to main content

ZProc - Process on steroids

Project description

ZProc lets you do shared-state multitasking without the perils of having shared-memory.

Behold, the power of ZProc:

# Some initialization
import zproc


ctx = zproc.Context(wait=True)  # wait for processes in this context
ctx.state["cookies"] = 0


# Define "atomic" operations

@zproc.atomic
def eat_cookie(state):
    """Eat a cookie."""

    state["cookies"] -= 1
    print("nom nom nom")


@zproc.atomic
def bake_cookie(state):
    """Bake a cookie."""
    state["cookies"] += 1
    print("Here's a cookie!")


# Fire up processes

@ctx.call_when_change('cookies')
def cookie_eater(_, state):
    """Eat cookies as they're baked."""

    eat_cookie(state)


for i in range(5):
    bake_cookie(ctx.state)

Result:

Here's a cookie!
Here's a cookie!
nom nom nom
Here's a cookie!
nom nom nom
Here's a cookie!
nom nom nom
Here's a cookie!
nom nom nom
nom nom nom

(baker and eater run in different processes)

The core idea

ZProc tries to breathe new life into the archaic idea of shared-state multitasking by protecting application state with logic and reason.

Shared state is frowned upon by almost everyone, (mostly) due to the fact that memory is inherently dumb.

Like memory doesn't really care who's writing to it.

ZProc's state tries to keep a track of who's doing what.

The Goal

ZProc aims to make building multi-taking applications easier and faster for everyone, in a pythonic way.

It started out from the core idea of having a smart state -- eventually wanting to turn into a full-fledged framework for all things multitasking.

Install

$ pip install zproc

Or, from the development branch

$ pip install git+https://github.com/pycampers/zproc.git@next#egg=zproc

License: MIT License (MIT)
Requires: Python >=3.5

Documentation ( Documentation Status )

Read the docs

Examples

Features

  • 🌠   Process management

    • Process Factory
    • Remembers to kill processes when exiting, for general peace. (even when they're nested)
    • Keeps a record of processes created using ZProc.
    • 🔖
  • 🌠   Process Maps

    • Automatically manages worker processes, and delegates tasks to them.
    • 🔖
  • 🌠   Asynchronous paradigms without async def

    • Build a combination of synchronous and asynchronous systems, with ease.
    • By watching for changes in state, without Busy Waiting.
    • 🔖
  • 🌠   Atomic Operations

    • Perform an arbitrary number of operations on state as a single, atomic operation.
    • 🔖

Caveats

  • The state only gets updated if you do it directly.
    This means that if you mutate objects inside the state, they wont get reflected in the global state.

  • The state should be pickle-able.

  • It runs an extra Process for managing the state.
    Its fairly lightweight though, and shouldn't add too much weight to your application.

FAQ

  • Fast?

    • Above all, ZProc is written for safety and the ease of use.
    • However, since its written using ZMQ, it's plenty fast for most stuff.
    • Run -> 🔖 for a taste.
  • Stable?

    • Mostly. However, since it's still in the 0.x.x stage, you can expect some API changes.
  • Production ready?

    • Please don't use it in production right now.
  • Windows compatible?

    • Probably?

Local development

git clone https://github.com/pycampers/zproc.git

cd zproc
pipenv install
pipenv install -d

pipenv shell

pip install -e .

pytest 

Build documentation

Assuming you have sphinx installed (Linux)

cd docs
./build.sh 

./build.sh loop  # starts a build loop.

ZProc in the wild

Thanks

  • Thanks to open logos for providing the wonderful ZProc logo.
  • Thanks to pieter hintjens, for his work on the ZeroMQ library and for his amazing book.
  • Thanks to tblib, ZProc can raise First-class Exceptions from the zproc server!
  • Thanks to psutil, ZProc can handle nested procesess!
  • Thanks to Kennith Rietz. His setup.py was used to host this project on pypi. Plus a lot of documentation structure is blatantly copied from his documentation on requests

ZProc is short for Zero Process.


🐍🏕️

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zproc-1.0.0a1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

zproc-1.0.0a1-py2.py3-none-any.whl (35.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file zproc-1.0.0a1.tar.gz.

File metadata

  • Download URL: zproc-1.0.0a1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2

File hashes

Hashes for zproc-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 25a8f33cfa83a6ad00f97cbc3e23b64a80eecbc3ea8eec49eebce80ab13798f2
MD5 40ed3d73a7dff7d8e267568750ff1690
BLAKE2b-256 cebdabd8152780483d11f89eb923fd9f6f8fcb7af2430970f9a23bd4a200b201

See more details on using hashes here.

File details

Details for the file zproc-1.0.0a1-py2.py3-none-any.whl.

File metadata

  • Download URL: zproc-1.0.0a1-py2.py3-none-any.whl
  • Upload date:
  • Size: 35.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.5.2

File hashes

Hashes for zproc-1.0.0a1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1ce6bed0724ead6fc7227baa0892453d22a0e002ea6f3b10a8e83ec987f6c07a
MD5 5afd16fd65e4f1a337abb86c221d4285
BLAKE2b-256 b0049de7fb0aae663e59317a3cbcd80398cdc0f91b5717b053ead0d60b989fad

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page