简体   繁体   中英

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. For example, when I run:

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 .

NOTE: I'd prefer to utilise the daemon package in Python 3.

On POSIX-compliant systems it is possible to pass the process arbitrary data locally with unix domain sockets. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM