如何实现简单的跨平台Python守护程序? [英] How do I implement a simple cross platform Python daemon?

查看:80
本文介绍了如何实现简单的跨平台Python守护程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的Python程序作为后台程序在Windows或Unix上在后台运行。我看到 python-daemon软件包仅适用于Unix;跨平台有替代方案吗?可能的话,我想使代码尽可能简单。

I would like to have my Python program run in the background as a daemon, on either Windows or Unix. I see that the python-daemon package is for Unix only; is there an alternative for cross platform? If possible, I would like to keep the code as simple as I can.

推荐答案

有两个选择:


  1. 移植程序 Windows服务。您可能可以在两个实现之间共享许多代码。

  1. Port your program into a windows service. You can probably share much of your code between the two implementations.

您的程序是否真的使用了守护程序功能?如果不是,则将其重写为在后台运行的简单服务器,通过套接字管理通讯并执行其任务。它可能比守护程序消耗更多的系统资源,但是它将独立于报价平台。

Does your program really use any daemon functionality? If not, you rewrite it as a simple server that runs in the background, manages communications through sockets, and perform its tasks. It will probably consume more system resources than a daemon would, but it would be quote platform independent.

这篇关于如何实现简单的跨平台Python守护程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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