Coder Social home page Coder Social logo

charmer's Introduction

Concurrency in Python is hard. Use Elixir instead.

Charmer is a minimal, somewhat configurable Elixir library for creating and interacting with a pool of Python processes. While this package was used in a production environment for well over a year, it has not been exercised beyond its initial specific use case.

Usage example

The following small example adds 1 to each element of a list of numbers by fanning the work over 4 Python worker processes:

Charmer.start_link(python_path: <path to Python code>, pool_size: 4)

1..5
|> Task.async_stream(&Charmer.call(<relative path to called Python module>, "inc", [&1]))
|> Enum.map(fn {:ok, x} -> x end)

Charmer.stop()

This returns the expected result [2, 3, 4, 5, 6].

In the above snippet, <path to Python code> is the root directory holding the Python code, and <relative path to called Python module> is the relative path of the module containing the called function--inc in this case.

The Python process pool is first started with Charmer.start_link, which takes a number of optional arguments, including :pool_size for the number of workers, and :pool_max_overflow for the number of additional workers that can be added to accommodate extra load. Charmer.stop terminates the supervisor process and all of its linked workers.

Foundation

This package uses Poolboy to create and interact with an OTP process pool, and Export to interact with each of the Python runtimes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.