From: Axel Kohlmeyer (axel.kohlmeyer_at_theochem.ruhr-uni-bochum.de)
Date: Wed Jun 30 2004 - 16:39:38 CDT

On Wed, 30 Jun 2004, John Stone wrote:

john,

now that i know about the existence of 'after',
i personally don't have a problem using it.

my idea was simply, that _other_ people might
also be tempted to use sleep (and get confused
that e.g. 'sleep 0.5' or 'sleep 1.5' does not
give the expected result, like i was). so my
suggestion still would be, to either change
the implementation of sleep or at least mention
'after' in the documentations of sleep.

for example:
sleep only stops execution for full seconds. if you want
to have a shorter delay in your script, you can use
'after \emph{n}' where 'n' are milliseconds.

sorry for not being to the point.
today was a looong day...

        axel.

JS>
JS> Axel,
JS> I suppose a simple Tcl proc could take a floating point number
JS> of seconds and convert it to the integer part and fractional part
JS> and do the required 'sleep' and 'after ms' calls to get the right delay,
JS> this could be done in Tcl itself like this:
JS>
JS> proc floatsleep { seconds } {
JS> if ([expr $seconds > 0.0]) {
JS> set secs [expr int($seconds)]
JS> set frac [expr fmod($seconds, 1)]
JS> set ms [expr int($frac * 1000)]
JS> sleep $secs
JS> after $ms
JS> }
JS> }
JS>
JS> It seems to be fairly usable for smallish delay values:
JS> vmd> time {floatsleep 0.09}
JS> 91280 microseconds per iteration
JS>
JS> It will not be as nice as a C-based implementation for small delay values,
JS> but it ought to be an easy-to-use substitute for the time being.
JS> Let me know if that is good enough for what you have in mind,
JS> I just whipped it up just now so it may not be 100%
JS> bulletproof yet. Give it a try and tell me what you think.
JS>
JS> John Stone
JS> vmd_at_ks.uiuc.edu
JS>
JS> On Wed, Jun 30, 2004 at 09:45:31PM +0200, Axel Kohlmeyer wrote:
JS> > On Wed, 30 Jun 2004, John Stone wrote:
JS> >
JS> >
JS> > john,
JS> >
JS> > indeed this is very nice. yet, it would be
JS> > even more convenient to have the sleep command
JS> > accept a floating point number and convert
JS> > that internally to milliseconds. that was my
JS> > initial motivation behind posting the select
JS> > based sleep (only i forgot to explain it in detail),
JS> > and i think i was not the only one trying to
JS> > wait a sub-second delay with the sleep command...
JS> >
JS> > axel.
JS> >
JS> > JS>
JS> > JS> Axel,
JS> > JS> Even better, as it turns out, there's already a Tcl command
JS> > JS> to delay for a specified number of milliseconds.
JS> > JS>
JS> > JS> Compare this:
JS> > JS> foreach {i} [info functions] {
JS> > JS> puts $i;
JS> > JS> }
JS> > JS>
JS> > JS> To this:
JS> > JS> foreach {i} [info functions] {
JS> > JS> # sleep for 250 milliseconds
JS> > JS> after 250
JS> > JS> puts $i;
JS> > JS> }
JS> > JS>
JS> > JS> Enjoy,
JS> > JS> John Stone
JS> > JS> vmd_at_ks.uiuc.edu
JS> > JS>
JS> >
JS> > [...]
JS> >
JS> > --
JS> >
JS> > =======================================================================
JS> > Dr. Axel Kohlmeyer e-mail: axel.kohlmeyer_at_rub.de
JS> > Lehrstuhl fuer Theoretische Chemie Phone: ++49 (0)234/32-26673
JS> > Ruhr-Universitaet Bochum - NC 03/53 Fax: ++49 (0)234/32-14045
JS> > D-44780 Bochum http://www.theochem.ruhr-uni-bochum.de/~axel.kohlmeyer/
JS> > =======================================================================
JS> >
JS>
JS>

-- 
=======================================================================
Dr. Axel Kohlmeyer                        e-mail: axel.kohlmeyer_at_rub.de
Lehrstuhl fuer Theoretische Chemie          Phone: ++49 (0)234/32-26673
Ruhr-Universitaet Bochum - NC 03/53         Fax:   ++49 (0)234/32-14045
D-44780 Bochum  http://www.theochem.ruhr-uni-bochum.de/~axel.kohlmeyer/
=======================================================================