Permalink
Browse files

Make examples work on Windows and add timeouts on receive

  • Loading branch information...
1 parent adf544f commit 77e650fdb880432abcb8b92082e1fad5649e5649 Dmitry Vasiliev committed Jan 9, 2010
Showing with 20 additions and 11 deletions.
  1. +6 −3 examples/generator.erl
  2. +1 −1 examples/generator.py
  3. +6 −3 examples/handler.erl
  4. +1 −1 examples/handler.py
  5. +5 −2 examples/hello.erl
  6. +1 −1 examples/hello.py
View
@@ -1,14 +1,17 @@
-module(generator).
-export([generate/1]).
-generate(N) when N >= 0 ->
- Port = open_port({spawn, "python handler.py"},
- [{packet, 4}, nouse_stdio, binary, {env, [{"PYTHONPATH", "../src"}]}]),
+generate(N) when is_integer(N) andalso N >= 0 ->
+ Port = open_port({spawn, "python -u handler.py"},
+ [{packet, 4}, binary, {env, [{"PYTHONPATH", "../src"}]}]),
generate(Port, N),
receive
{Port, {data, Data}} ->
port_close(Port),
binary_to_term(Data)
+ after
+ 500 ->
+ {error, timeout}
end.
generate(Port, 0) ->
View
@@ -15,4 +15,4 @@ def handle(self, port, n):
if __name__ == "__main__":
proto = EventGenerator()
- proto.run(Port())
+ proto.run(Port(use_stdio=True))
View
@@ -1,9 +1,9 @@
-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"}]}]),
+handle(N) when is_integer(N) andalso N >= 0 ->
+ Port = open_port({spawn, "python -u generator.py"},
+ [{packet, 1}, binary, {env, [{"PYTHONPATH", "../src"}]}]),
port_command(Port, term_to_binary(N)),
handle(Port, []).
@@ -17,4 +17,7 @@ handle(Port, Acc) ->
Term ->
handle(Port, [Term | Acc])
end
+ after
+ 5000 ->
+ {error, timeout}
end.
View
@@ -17,4 +17,4 @@ def handle(self, port, message):
if __name__ == "__main__":
proto = EventHandler()
- proto.run(Port(packet=4))
+ proto.run(Port(packet=4, use_stdio=True))
View
@@ -2,11 +2,14 @@
-export([hello/1]).
hello(Name) when is_list(Name) ->
- Port = open_port({spawn, "python hello.py"},
- [{packet, 1}, nouse_stdio, binary, {env, [{"PYTHONPATH", "../src"}]}]),
+ Port = open_port({spawn, "python -u hello.py"},
+ [{packet, 1}, binary, {env, [{"PYTHONPATH", "../src"}]}]),
port_command(Port, term_to_binary({hello, Name})),
receive
{Port, {data, Data}} ->
port_close(Port),
binary_to_term(Data)
+ after
+ 500 ->
+ {error, timeout}
end.
View
@@ -9,4 +9,4 @@ def handle_hello(self, name):
if __name__ == "__main__":
proto = HelloProtocol()
- proto.run(Port())
+ proto.run(Port(use_stdio=True))

0 comments on commit 77e650f

Please sign in to comment.