No, this is not the processor intensity.
The documentation says:
Pause execution for a specified number of seconds.
Python cannot guarantee that in any possible implementation, this means that the OS will never schedule your process during sleep. But on each platform, Python is trying to do something suitable for locking for the specified time without using any CPU. On some platforms, this may mean a little processor, but it will be as small as possible.
In particular, since you asked about Linux and supposedly CPython:
On Linux and most other POSIX platforms, select is commonly used. See source 3.3 .
The page makes it pretty clear that select paused until a signal, timeout, or finished I / O (and in this case there is no fds, so the latter is not possible).
You can read the kernel source code for complete information, but in principle, if there are no unexpected signals, you will not be planning at all, with the possible exception of a tiny amount of rotation at the very beginning of select (as an optimization for cases where select can come back almost immediately).
In the middle of your resume, the question changes from "is sleep CPU intensive" to "should I use sleep or the cron job?"
In any case, you do not burn any processor while waiting. There are some pros and cons, but most of them are trivial. From the (rude and subjective) cron's least important job:
- allows you to configure, for example, change the schedule without editing the source code.
- requires the configuration to work.
- means less code, which means fewer errors and less for any future readers.
- will be saved when the system shuts down.
- will run again even if your script exits with an exception or signal.
- can fire either 0, 1, or N times if its scheduled interval is skipped N times (this is not indicated, and different cron implementations do different things) instead of the guaranteed 0.
- is more likely to handle system clock changes.
- must pay to start the process, start the interpreter, etc. every time it fires.
- does not lose the table table and processes the table space because there is no process and the memory card is not displayed.
abarnert
source share