与正在运行的python守护程序进行通信 [英] Communicating with a running python daemon

查看:111
本文介绍了与正在运行的python守护程序进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个作为守护程序运行的小型Python应用程序。它利用线程和队列。

I wrote a small Python application that runs as a daemon. It utilizes threading and queues.

我正在寻找更改此应用程序的常规方法,以便在运行时与其进行通信。通常,我希望能够监视它的健康。

I'm looking for general approaches to altering this application so that I can communicate with it while it's running. Mostly I'd like to be able to monitor its health.

总而言之,我希望能够执行以下操作:

In a nutshell, I'd like to be able to do something like this:

python application.py start  # launches the daemon

稍后,我希望能够进行以下操作:

Later, I'd like to be able to come along and do something like:

python application.py check_queue_size  # return info from the daemonized process

返回信息要明确,我没有任何问题实现Django启发式语法。我不知道该怎么做是将信号发送到守护进程(开始),或者如何编写守护进程来处理和响应此类信号。

To be clear, I don't have any problem implementing the Django-inspired syntax. What I don't have any idea how to do is to send signals to the daemonized process (start), or how to write the daemon to handle and respond to such signals.

就像我上面说的那样,我正在寻找通用的方法。我现在唯一能看到的就是告诉守护程序不断将可能需要的所有内容记录到文件中,但是我希望有一种更简单的方法来处理它。

Like I said above, I'm looking for general approaches. The only one I can see right now is telling the daemon constantly log everything that might be needed to a file, but I hope there's a less messy way to go about it.

更新:哇,很多不错的答案。非常感谢。我想我会同时研究Pyro和web.py/Werkzeug的方法,因为Twisted远远超出了我现在想咬的范围。我想,下一个概念性挑战是如何在不挂断我的工作线程的情况下进行交谈。

UPDATE: Wow, a lot of great answers. Thanks so much. I think I'll look at both Pyro and the web.py/Werkzeug approaches, since Twisted is a little more than I want to bite off at this point. The next conceptual challenge, I suppose, is how to go about talking to my worker threads without hanging them up.

再次感谢。

推荐答案

如何运行http服务器呢?

What about having it run an http server?

这似乎很疯狂,但为它运行一个简单的Web服务器使用web.py

It seems crazy but running a simple web server for administrating your server requires just a few lines using web.py

管理
服务器只需要几行。您还可以考虑创建unix管道。

You can also consider creating a unix pipe.

这篇关于与正在运行的python守护程序进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆