在Python中创建[self]respawning应用程序的正确方法

发布于 2024-08-28 00:37:22 字数 279 浏览 3 评论 0原文

我正在使用用 python 编写的 jabber 机器人来记录一些 MUC 谈话。有时它会因某些网络或 XMPP 问题而下降。在这种情况下,我必须自己重新开始。目标是使其“自我重生”。

关于如何做到这一点,我有一些变体。

  1. Bot 是一个进程。另一个过程 监视其活动并启动它 如果机器人死了。
  2. 主进程产生机器人 子进程并控制它。

我还认为守护机器人进程在这里很有用。 正如您所猜到的,平台是 Linux。

解决这个问题的正确方法是什么?

I am using jabber bot written in python to log some MUC talks. Sometimes it drops on some network or XMPP problems. In this case I have to start it again by myself. The goal is to make it "self-respawning".

I have some variants about how to do it.

  1. Bot is one process. Another process
    monitors its activity and starts it
    if bot died.
  2. Main process spawns bot
    subprocess and controls it.

Also I think daemonizing bot process is useful here.
Platform is Linux, as you could guess.

What is the right way to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2024-09-04 00:37:22

如果您使用的是 ubuntu 之类的东西,请尝试研究 upstart 及其自动守护进程和“重生”功能。这是一篇很好的关于运行与启动进程的一般博客文章

我还听说过有关 supervisdord 的好消息。

If you're using something like ubuntu, try looking into upstart and its automatic daemonization and "respawn" feature. Here's a good general blogpost about running vs. starting processes.

I've also heard good things about supervisdord.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文