Doktor J
Doktor J

Reputation: 1118

Python: threading or multiprocessing?

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.

Upvotes: 1

Views: 606

Answers (1)

Sven Marnach
Sven Marnach

Reputation: 602155

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.

Upvotes: 4

Related Questions