time.sleep() and cpu cycles

Timothy Grant tjg at exceptionalminds.com
Fri Feb 9 20:53:14 EST 2001


On Fri, Feb 09, 2001 at 02:19:34PM -0500, Tim Peters wrote:
> [Timothy Grant]
> > ... Linux ... (kernel 2.2.14).
> >
> > ... python logging script that reads the inode info out of /proc
> > every 10 seconds, and then uses python's logging facilities
> 
> What are those?  "print"?

actually, syslog. I once wrote an app where I logged everything using print
statements, syslog just brings too many nice bits to the game to not use it.
 
> > to write out a log file with what it found.
> > ...
> > When the box is under load with users logged running things, the
> > python process does not interfere with anything.
> > ...
> > However, on an unloaded system, the python process is taking 60%
> > of the CPU.  Maybe that's the way it should be, but it sure seemed
> > odd to me.
> 
> Me too.

We're gonna go back and look some more, just because we are curious types!

 
> > I use time.sleep() for my delay loop, and was wondering if there
> > is a better way to put a task to sleep,
> 
> No.

Glad to hear it. I thought it must be the "right" way as I saw no mention of
any other method of doing it, but I thought I might be missing something
too.
 
> > or if what I'm seeing is normal behaviour.
> 
> Certainly not normal behavior under Windows <wink>.  But unlike most of
> Python's platform-dependent functions, time.sleep() isn't just a thin
> wrapper around the C library function of the same name.  It eventually calls
> Modules/timemodule.c's floatsleep(), which strives to shut the task up with
> the finest-grain precision it can get on each platform, by hook or by crook.

Thanks Tim for the informative and enlightening post. Much appreciated, I
thought maybe I had run into one of those well coded extremely tight polling
loops that used to crop up DOS programmes<wink>.



-- 
Stand Fast,
    tjg.

Timothy Grant                         tjg at exceptionalminds.com
Red Hat Certified Engineer            www.exceptionalminds.com
Avalon Technology Group, Inc.                   (503) 246-3630
>>>>>>>>>>>>>Linux, because rebooting is *NOT* normal<<<<<<<<<
>>>>This machine was last rebooted:  24 days  5:58 hours ago<<




More information about the Python-list mailing list