【问题标题】:Passing Messages with PID to Erlang from Python using ErlPort使用 ErlPort 从 Python 将带有 PID 的消息传递给 Erlang
【发布时间】:2014-09-17 02:22:06
【问题描述】:

我想以{From(PID}, atom} 格式从python 向Erlang 传递消息,因为我的erlang 程序需要知道要向哪个进程ID 发送消息。

Erlang 消息循环:

message_loop([First | Rest]) -> 
receive 
    {From, ready} ->
        % From ! {self(), {read, First}},
        python:cast(From, {read, First}),
        message_loop(Rest);
    {From, done} ->
        python:cast(From, {read, First}), 
        message_loop(Rest);
    {From, _} ->
        io:format("Invalid Message Received From");
    _ ->
        io:format("Random Message")
end.

如何使用 ErlPort 传递这样的消息?或者在产生许多进程后,我可以使用任何其他技术来选择性地与进程通信吗?

【问题讨论】:

标签: python erlang


【解决方案1】:

正如您在记录的types mapping 中看到的那样,没有自动执行此操作的选项。

您可以做的是将PID 转换为带有erlang:pid_to_list/1 的字符串表示形式,并将其发送到python。从 python 接收时,您可以使用erlang:list_to_pid/1。这应该够用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-15
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 2016-04-30
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多