[英]Could someone explain how a python daemon can also function to communicate with a running instance of itself?
I'd like to implement a Python module that functions as a daemon and as an interface to that daemon. 我想实现一个Python模块,该模块充当守护程序和该守护程序的接口。 For example, when I run: 例如,当我运行时:
python daemon.py do_something python daemon.py do_something
The daemon
module should try to communicate to the daemon to do_something
, and if it doesn't exist, start the daemon and then do_something
. daemon
模块应尝试与守护程序通信以进行do_something
,如果不存在,请启动守护程序,然后启动do_something
。
NOTE: I'd prefer to utilise the daemon package in Python 3. 注意:我更喜欢在Python 3中使用守护程序包。
On POSIX-compliant systems it is possible to pass the process arbitrary data locally with unix domain sockets. 在符合POSIX的系统上,可以使用unix域套接字在本地传递过程任意数据。 You can create both client and server socket using socket module . 您可以使用套接字模块创建客户端套接字和服务器套接字。 Parsing command line options (for example, using optparse or argparse modules) you can decide whether the daemon should be started or client socket connection opened to pass the command. 通过解析命令行选项(例如,使用optparse或argparse模块),您可以决定是启动守护程序还是打开客户端套接字连接以传递命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.