How to insert sleep for 30 seconds in tcl script?
Asked Answered
C

3

9

I want to insert sleep for 30 second in my TCL script.

I tried using sleep command. but its not working. could any one of you help on this?

Complimentary answered 9/8, 2014 at 14:52 Comment(1)
Tcl doesn't have a "sleep" command: tcl.tk/man/tcl8.6/TclCmd/contents.htm -- Expect does though: man.cx/expectPimento
P
18

You have to use

after 30000

The argument to after is interpreted as milliseconds.
While asking a question, if you insert your code, that will be useful for others.

Plague answered 9/8, 2014 at 15:13 Comment(1)
Note that this halts event processing in the thread while sleeping.Bootee
S
1

As previously stated by Donal Fellows in the comments, rcubefather's solution will halt event processing while sleeping.

Here's a slightly different approach I use is:

after 30000 set stop_wait &
vwait stop_wait
unset stop_wait

This will put the 'after 30000' command in background (&) waiting for 'stop_wait' variable to be set, while any other event processing will not be halted. This behavior is much more evident working with Tk GUI. However this will not prevent 'vwait' command from catching up the variable when set, allowing this portion of code to proceed. Not CPU intensive as well.

Sanders answered 9/11, 2019 at 9:14 Comment(1)
This gives me "can't unset "stop_wait": no such variable" on TCL 8.5 for Windows. But following works for me: set stop_wait X; after 30000 {set stop_wait Y}; vwait stop_wait; unset stop_waitDiencephalon
G
0

If you are in a Linux environment, you can use any Linux command.

Example:

puts [date] ; exec sleep 10 ; puts [date]

will yield:

Mon Feb 24 10:09:08 IST 2020
Mon Feb 24 10:09:18 IST 2020

Just make sure you have such command by typing which sleep in a Linux shell.

Grizel answered 24/2, 2020 at 8:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.