- 使用os.execute 执行涉及等待、超时的外部命令、程序。配合 >nul 不显示标准输出流信息。执行过程是阻塞(block)等待的。
- os.execute"ping 1.1.1.1 /n 1 /w <time in milliseconds> >nul" ,如os.execute"ping 1.1.1.1 /n 1 /w 1000 >nul" 。
- os.execute"CHOICE /n /d:y /c:yn /t:1 >nul" 。
- 为(Windows)系统安装GNU命令包(minGW?)。
>sleep --help
Usage: sleep NUMBER[SUFFIX]...
or: sleep OPTION
Pause for NUMBER seconds. SUFFIX may be `s' for seconds (the default),
`m' for minutes, `h' for hours or `d' for days. Unlike most implementations
that require NUMBER be an integer, here NUMBER may be an arbitrary floating
point number.--help display this help and exit
--version output version information and exitReport bugs to <bug-coreutils@gnu.org>.
进而可以 os.execute"sleep 1" 。
- 使用库。
- require'socket'.select(nil,nil,sec) (9.4 – Non-Preemptive Multithreading - Programming in Lua)
- require'luasocket'.sleep(sec) LuaSocket: Network support for the Lua language)
-
- require'iuplua'.timer{TIME=millisec,action_cb=function()end}
- 整理参考:Easiest way to make lua script wait/pause/sleep/block for a few seconds? - Stack Overflow,avoid lua wait time loop while high cpu - Google 搜索,how to yield lua function idle when monitor file wait time high cpu - Google 搜索(useless),lua return yield cpu consume - Google 搜索(useless),Lua sockets - Asynchronous Events - Stack Overflow(LuaSocket + Lua Lanes/多线程、lua-ev)