Kumar
Kumar

Reputation: 717

How to insert sleep for 30 seconds in tcl script?

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?

Upvotes: 9

Views: 41454

Answers (3)

Amit Erez
Amit Erez

Reputation: 11

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.

Upvotes: 0

Losko
Losko

Reputation: 11

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.

Upvotes: 1

rcubefather
rcubefather

Reputation: 1564

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.

Upvotes: 18

Related Questions