-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dmitry Vasiliev
committed
Jan 2, 2010
1 parent
0d1c090
commit bf5c1bf
Showing
7 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
*.swp | ||
*.pyc | ||
*.py[co] | ||
*.beam | ||
/src/*.egg-info | ||
/build | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-module(generator). | ||
-export([generate/1]). | ||
|
||
generate(N) when N >= 0 -> | ||
Port = open_port({spawn, "python handler.py"}, | ||
[{packet, 1}, nouse_stdio, binary, {env, [{"PYTHONPATH", "../src"}]}]), | ||
generate(Port, N), | ||
receive | ||
{Port, {data, Data}} -> | ||
port_close(Port), | ||
binary_to_term(Data) | ||
end. | ||
|
||
generate(Port, 0) -> | ||
port_command(Port, term_to_binary(stop)); | ||
generate(Port, N) -> | ||
port_command(Port, term_to_binary(now())), | ||
generate(Port, N - 1). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import time | ||
|
||
from erlport import Port, Protocol | ||
from erlport import Atom | ||
|
||
|
||
class EventGenerator(Protocol): | ||
|
||
def handle(self, port, n): | ||
while n > 0: | ||
port.write(tuple(time.localtime())) | ||
n -= 1 | ||
port.write(Atom("stop")) | ||
|
||
|
||
if __name__ == "__main__": | ||
proto = EventGenerator() | ||
proto.run(Port()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-module(handler). | ||
-export([handle/1]). | ||
|
||
handle(N) when N >= 0 -> | ||
Port = open_port({spawn, "python generator.py"}, | ||
[{packet, 1}, nouse_stdio, binary, {env, [{"PYTHONPATH", "../src"}]}]), | ||
port_command(Port, term_to_binary(N)), | ||
handle(Port, []). | ||
|
||
handle(Port, Acc) -> | ||
receive | ||
{Port, {data, Data}} -> | ||
case binary_to_term(Data) of | ||
stop -> | ||
port_close(Port), | ||
lists:reverse(Acc); | ||
Term -> | ||
handle(Port, [Term | Acc]) | ||
end | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from erlport import Port, Protocol | ||
from erlport import Atom | ||
|
||
|
||
class EventHandler(Protocol): | ||
|
||
def __init__(self): | ||
self.collected = [] | ||
|
||
def handle(self, port, message): | ||
if message == Atom("stop"): | ||
port.write(self.collected) | ||
self.collected = [] | ||
else: | ||
self.collected.append(message) | ||
|
||
|
||
if __name__ == "__main__": | ||
proto = EventHandler() | ||
proto.run(Port()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-module(hello). | ||
-export([hello/1]). | ||
|
||
hello(Name) -> | ||
Port = open_port({spawn, "python hello.py"}, | ||
[{packet, 1}, nouse_stdio, binary, {env, [{"PYTHONPATH", "../src"}]}]), | ||
port_command(Port, term_to_binary({hello, Name})), | ||
receive | ||
{Port, {data, Data}} -> | ||
port_close(Port), | ||
binary_to_term(Data) | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from erlport import Port, Protocol | ||
|
||
|
||
class HelloProtocol(Protocol): | ||
|
||
def handle_hello(self, name): | ||
return "Hello, %s" % name | ||
|
||
|
||
if __name__ == "__main__": | ||
proto = HelloProtocol() | ||
proto.run(Port()) |