Examples!¶
Talk is cheap! Show me some code!
Have a look in Cookbook - How to Get Started too!
Some examples are located in examples/
directory. And there are convenient
Makefile
targets to call them, just use your Bash autocomplete when typing
make example<TAB>
:
1: Python to Erlang¶
Demonstrates how Python node can actively find a running Erlang node and connect to it by attempting to send a message.
Running (in two terminal tabs):
Start Erlang node with
erl -name erl@127.0.0.1 -setcookie COOKIE
.(optional) Register your shell process as
shell
by executing in the Erlang shell:erlang:register(shell, self()).
make example1
- will start a node atpy@127.0.0.1
and using cookieCOOKIE
will try to connect to Erlang running aterl@127.0.0.1
;(optional) Check whether Erlang shell received
hello
by typingflush().
2: Erlang to Python¶
Demonstrates how to run a named process on Python node. Erlang node will try and send message to it by name.
make example2
- will register a process asmy_process
and you can send messages to it by name from Erlang;Start Erlang node with
erl -name erl@127.0.0.1 -setcookie COOKIE
.In Erlang shell try send something to
my_process
like this:{my_process, 'py@127.0.0.1'} ! {hello, 123, [<<"test">>, self()]}.
In Python terminal tab observe log message about incoming data.
3 & 4: Calling/Batch Python¶
Examples are .erl
files which demonstrate how remote notebook-style calls
and batch calls will work with Erlang and Python.
make pynode
(same asmake example2
) to get a running Python node.make example3
ormake example4
and observe what it prints.
5: Links and Monitors of Pyrlang Processes¶
Demonstrates Erlang remotely monitoring and linking to Pyrlang processes.
A Python Process
will trigger monitor and link
messages when exiting.
make example5a
will start Erlang node.make example5b
(in another terminal) will start Python Pyrlang node.Pyrlang node will send a message starting the test.
Erlang node will spawn a test process, report its pid to Python node.
Python node (now knowing the pid) will monitor the Erlang process.
Python node will send a exit message to Erlang side, and observe the monitor message arriving back.
6 & 7: Links/Monitors of Erlang Processes¶
Demonstrates Pyrlang remotely linking to and monitoring an Erlang process.
Note
For linking demo use 'example6a' and 'example6b', for monitoring demo use 'example7a', 'example7b' Makefile targets.
make example6a
will start Erlang node.make example6b
(in another terminal) will start Python Pyrlang node.Pyrlang node will send a message starting the test.
Erlang node will spawn a test process, report its pid to Python node.
Python node (now knowing the pid) will monitor the Erlang process.
Python node will send a exit message to Erlang side, and observe the monitor message arriving back.
10: Elixir and GenServer¶
This example will demonstrate how to accept gen_server:call
in your Python
Process
.
Running (in two terminal tabs):
make example10a
- will start Python part of Example 10 and start aGenServer
example;make example10b
- will start Elixir part of Example 10 and perform 2gen_server:call
'sIn Elixir terminal tab observe results for 1st and 2nd calls.
Note
Some examples require a client and a server, these have two parts: example A and example B.