使用ErlP从Python向Erlang传递带有PID的消息

2024-04-26 21:11:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望以{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.

如何使用erport传递这样的消息?或者有没有其他技术可以用来在产生许多进程之后有选择地与进程通信?在


Tags: fromiolooprestformat消息messageread
1条回答
网友
1楼 · 发布于 2024-04-26 21:11:03

正如您在文档中看到的types mapping没有自动执行的选项。在

您可以使用PIDPID转换为字符串表示,并将其发送给python。从python接收时,可以使用erlang:list_to_pid/1。那就足够了。在

相关问题 更多 >