Code Monkey home page Code Monkey logo

snek.ex's Introduction

snek

Description

Example repository to show what the equivalents of the Erlang/Python examples on this page look like so that they work in an Elixir/Mix application.

Currently both functionalities work, as well as calling your own Python scripts from BEAM.

Usage

git clone http://github.com/arthurcolle/elixir-snake
cd elixir-snake
source activate <name of python virtualenv>
mix deps.get
mix compile
iex -S mix run

Other than having Python 2.7.9 installed (I used Anaconda) you should be good. Please feel free to submit pull requests, or even add cooler examples!

Example 1: Simple call to Python

SNEK.cmd(cmd)

Note: only currently supported command is :vzn for py version. More will come in time.

iex(3)> SNEK.cmd(:vzn)

"3.9.9 |Continuum Analytics, Inc.| (default, Dec 15 2029, 10:37:34)
[GCC 4.2.1 (Apple Inc. build 5577)]"

Example 2: More complicated call to your own Python script

SNEK.b

iex(2)> SNEK.b
What's your name?
Arthur Colle
"Arthur Colle is a boss"

Example 3: Ouroboros - Elixir script that calls Python that calls Erlang (spawns processes)

SNEK.spawn_threads(num_threads)

iex(1)> SNEK.spawn_threads
You just spawned 999 processes in BEAM VM.
Here they are!
Tuple left element is an agent containing an array of threads.
Tuple right element is the process that runs the port connector to the python process
{#PID<0.165.0>,
[#PID<0.168.0>, #PID<0.169.0>, #PID<0.170.0>, #PID<0.171.0>, #PID<0.172.0>,
#PID<0.173.0>, #PID<0.174.0>, #PID<0.175.0>, #PID<0.176.0>, #PID<0.177.0>,
#PID<0.178.0>, #PID<0.179.0>, #PID<0.180.0>, #PID<0.181.0>, #PID<0.182.0>,
#PID<0.183.0>, #PID<0.184.0>, #PID<0.185.0>, #PID<0.186.0>, #PID<0.187.0>,
#PID<0.188.0>, #PID<0.189.0>, #PID<0.190.0>, #PID<0.191.0>, #PID<0.192.0>,
#PID<0.193.0>, #PID<0.194.0>, #PID<0.195.0>, #PID<0.196.0>, #PID<0.197.0>,
#PID<0.198.0>, #PID<0.199.0>, #PID<0.200.0>, #PID<0.201.0>, #PID<0.202.0>,
#PID<0.203.0>, #PID<0.204.0>, #PID<0.205.0>, #PID<0.206.0>, #PID<0.207.0>,
#PID<0.208.0>, #PID<0.209.0>, #PID<0.210.0>, #PID<0.211.0>, #PID<0.212.0>,
#PID<0.213.0>, #PID<0.214.0>, #PID<0.215.0>, ...]}

As you can see the above response is a tuple, left is the py proc (under the hood really its a port that enables messaging with another process via STDIN and STDOUT, in this case from the processes running in the BEAM VM <---> a running Python process. On the right, your list of processes is available

snek.ex's People

Contributors

reachfh avatar stochastic-thread avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

snek.ex's Issues

python:stop

Thanks for creating this awesome library!

Quick question. Am I supposed to somehow stop the python process after the python module is run? like :python.stop..

If so, how do I know when to stop python? (unless I know when the module execution is completed) I'm guessing I can put :python.stop right after :python.call, assuming they are run sequentially?

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.