[Python-Dev] PEP needed? Introducing Tcl objects

Tim Peters tim.one@comcast.net
Mon, 18 Feb 2002 23:57:22 -0500

[Jeff Hobbs]
> I guess I would need to get a better understanding of why it was
> designed with the sleep in the first place.  Martin mentioned
> that it allows a thread switch to occur, but a shorter sleep
> interval would have done the same.

I believe Martin was correct in large part.  The other part is that, without
a sleep at all, we would have a pure busy loop here, competing for cycles
non-stop with every process on the box.

About the length of the sleep, do note that Sleep(20) sleeps 20 milliseconds
here (not seconds), and that the sleep is skipped so long as
Tcl_DoOneEvent() says it's finding things to do.  IOW, Tcl gets all the
cycles it can it eat so long as it says it's busy, and doesn't generally
wait more than about 0.02 seconds for another chance after it runs out of
work to do.

Back when 20 was first picked, machines were slow enough that an utterly
idle Tkinter app in the background still showed up as consuming a measurable
percentage of a CPU, thanks to this not-so-busy loop.  We could afford to
make the sleep shorter on faster boxes, but I'm not sure I buy the argument
that we're making Tcl/Tk look sluggish.  The reason we hate the loop is more
that it's a miserably ugly hack.