Python:线程还是多处理?

发布于 2025-01-04 22:30:56 字数 314 浏览 1 评论 0原文

问题

我需要每 15 秒对文件进行一次简短写入(并在其余时间睡眠)...在我看来,通过使用专用线程或进程来执行多线程或多处理将有助于解决此问题文件写入。就时序/可靠性以及内存占用而言,哪个更好?

背景

我正在为 Chumby 编写一个小型 Python 应用程序(内存可用性非常有限——系统总内存为 128MB);为了阻止默认的 Chumby 控制面板在我杀死它后重新启动,需要每隔 15 秒左右写入一个临时文件,以“欺骗”通常会重新启动控制面板的看门狗进程。主应用程序可能正忙于做其他事情,我不想尝试必须“看时钟”,因为它正在做其他事情以确保它挤入临时文件写入。

Question

I need to make a short write to a file every 15 seconds (and sleep the rest of the time)... it seems to me that multithreading or multiprocessing would be useful to address this, by having a dedicated thread or process to do the file write. Which would be better in terms of timing/reliability, as well as memory footprint?

Background

I am writing a small Python application for a Chumby (so limited memory availability -- 128MB total system memory); to stop the default Chumby control panel from restarting after I've killed it, a temp file needs to be written to every 15 seconds or so to "fool" the watchdog process that would ordinarily restart the control panel. The main application may be busy doing other things, and I don't want to try to have to "watch the clock" as it's doing its other things to make sure it squeezes in the temp file write.

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

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

发布评论

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

评论(1

北凤男飞 2025-01-11 22:30:56

Chumby 似乎是基于 Linux 的,因此 signal.setitimer()< /code>应该可用(前提是您可以访问 Python 2.6 或更高版本)。

此函数允许您安装定期调用的处理程序,因此您不需要线程或进程。

The Chumby seems to be Linux-based, so signal.setitimer() should be available (provided you have access to Python 2.6 or above).

This function allows you to install a handler that is periodically called, so you don't need a thread or process.

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