本文介绍了简单的进程间通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种简单方式,将消息从一个进程(Perl脚本,短暂的)传递到另一个进程(Python脚本,长期运行)-这两个进程都位于同一台计算机上.我已经进行了一些研究,但发现的发现要么令我头疼,要么看起来不必要地复杂-让我有些迷茫和困惑.

I'm looking for a simple way to pass messages from one process (Perl script, short-lived) to another (Python script, long-running) - both processes local to the same machine.I've done some research, but what I've found was either over my head or seemed unnecessarily complex - leaving me a bit lost and confused.

我想象一个最小的示例,大致如下:

I imagine a minimal example roughly like the following:

# listener.py

class Listener:
    def __init__(self, port)
        self.port = port

    def on_message(self, msg):
        print "%s: %s" % (timestamp, msg)

recipient = Listener(1234)


# sender.pl

sub send_message {
    my ($msg, $port) = @_;
    # ...
}

send_message("hello world", 1234);

任何有关如何解决和/或在何处阅读的指针将不胜感激!

Any pointers on how to solve and/or where to read up on this would be greatly appreciated!

推荐答案

通常,您对套接字感兴趣.获取所需的大致信息的好地方是 IO ::的文档Socket :: INET 或来自 perldoc perlipc

In general you are interested in sockets. A good place to get just the needed rough information is the documentation of IO::Socket::INET or more basic socket-stuff in perl from perldoc perlipc

这篇关于简单的进程间通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:13