在 tcl 中处理每 10 个对象的睡眠命令
Sleep command for every 10 objects processed in tcl
我正在从 csv
文件中获取输入并在 tcl 中进行处理。我一直在尝试为从 csv 处理的每 10 行提供大约 2 分钟 时间间隔 。 csv 可能包含大约 500 行。所以它需要一些时间来处理这个。下面的代码是我的尝试。我对 tcl 没有任何知识,只是用谷歌搜索并尝试过,但这不起作用。
set fileIn [open "/mydir/Test3.csv" r]
set i 0
while {[gets $fileIn sLine] >= 0} {
incr i
if{$i==10} {
after 120000
set i 0
continue
}
set lsLine [split $sLine ","]
set sType [lindex $lsLine 0]
set sName [lindex $lsLine 2]
set sValue ""
set sCount [lindex $lsLine 3]
set sprice [lindex $lsLine 4]
# My other operations
}
也让我知道使用 after
还是 sleep
更好。
Tcl 中的间距很重要。您的 if 语句在 if.
之后需要一个 space
if{$i==10} {
应该看起来像
if {$i==10} {
由于您想每 2 分钟 运行 一次,因此您需要考虑前 10 项的处理时间。
set fileIn [open "Test3.csv" r]
set i 0
set start_ms [clock milliseconds]
while {[gets $fileIn sLine] >= 0} {
incr i
if {$i==10} {
set now_ms [clock milliseconds]
set timetaken_ms [expr {$start_ms - $now_ms}]
after [expr {120000 - $timetaken_ms}]
set start_ms [clock milliseconds]
set i 0
continue
}
set lsLine [split $sLine ","]
set sType [lindex $lsLine 0]
set sName [lindex $lsLine 2]
set sValue ""
set sCount [lindex $lsLine 3]
set sprice [lindex $lsLine 4]
# My other operations
puts "$sType - $sName - $sValue - $sCount - $sprice"
}
我正在从 csv
文件中获取输入并在 tcl 中进行处理。我一直在尝试为从 csv 处理的每 10 行提供大约 2 分钟 时间间隔 。 csv 可能包含大约 500 行。所以它需要一些时间来处理这个。下面的代码是我的尝试。我对 tcl 没有任何知识,只是用谷歌搜索并尝试过,但这不起作用。
set fileIn [open "/mydir/Test3.csv" r]
set i 0
while {[gets $fileIn sLine] >= 0} {
incr i
if{$i==10} {
after 120000
set i 0
continue
}
set lsLine [split $sLine ","]
set sType [lindex $lsLine 0]
set sName [lindex $lsLine 2]
set sValue ""
set sCount [lindex $lsLine 3]
set sprice [lindex $lsLine 4]
# My other operations
}
也让我知道使用 after
还是 sleep
更好。
Tcl 中的间距很重要。您的 if 语句在 if.
之后需要一个 spaceif{$i==10} {
应该看起来像
if {$i==10} {
由于您想每 2 分钟 运行 一次,因此您需要考虑前 10 项的处理时间。
set fileIn [open "Test3.csv" r]
set i 0
set start_ms [clock milliseconds]
while {[gets $fileIn sLine] >= 0} {
incr i
if {$i==10} {
set now_ms [clock milliseconds]
set timetaken_ms [expr {$start_ms - $now_ms}]
after [expr {120000 - $timetaken_ms}]
set start_ms [clock milliseconds]
set i 0
continue
}
set lsLine [split $sLine ","]
set sType [lindex $lsLine 0]
set sName [lindex $lsLine 2]
set sValue ""
set sCount [lindex $lsLine 3]
set sprice [lindex $lsLine 4]
# My other operations
puts "$sType - $sName - $sValue - $sCount - $sprice"
}