View Full Version : iTCL background routines possible?
b>d>>s
11-20-2003, 10:20 PM
is there a way to run some tcl in the background on io?, kinda like how dzsbot runs on utimer in eggdrop?
allowing io to continue normally ?
thanks
darkone
11-20-2003, 11:59 PM
Setup timer from itcl...
phoenixfr
11-21-2003, 05:51 AM
io can crash with those comands !?
dark0ne if that's true is there anything possible to make io crash proof with this
just don't like the idea that it's possible to crash
darkone
11-21-2003, 07:36 AM
With what commands? I can't protect tcl interpreter (if it crashes on invalid commands), as it's nothing but 3rd party add-on.
b>d>>s
11-21-2003, 11:19 AM
ah,cool. works. i thought timer just executed 'once', but it repeats over and over .. neat
thx
darkone
11-21-2003, 01:25 PM
Hmms, it shouldn't execute more than once per command :) You need to recall timer once per script run... so something like this should work:
mytimerscript.itcl
# do stuff
...
# stuff done
timer "TCL mytimerscript.itcl"
also you could protect your timer, so that there won't be multiple instances... here's a working hack, using spinlock - it might crash, if timer is stopped twice :)
proc mytimer_do { wo } {
putlog "timer is running"
timer 1000 "TCL ../scripts/timertest.itcl -timer $wo"
}
proc mytimer { wo } {
# Set status to unsignaled & return current status (0 = signaled, 1 = unsignaled)
if {[waitobject reset $wo]} {
# Timer has not been canceled
mytimer_do $wo
return
}
putlog "closing timer"
# Close waitobject permanently
waitobject delete $wo
return
}
if {[info exists args]} {
set argv [split $args]
# "-timer" is called by timer
if {[lindex $argv 0] == "-timer"} {
mytimer [lindex $argv 1]
return 0
}
# "-stop" is a parameter that stops the timer, on next timer instance
if {[lindex $argv 0] == "-stop"} {
set wo [waitobject open "myprotector" spinlock]
if {$wo} {
# Set status to signaled
putlog "Stopping timer"
if {[waitobject set $wo]} {
# Could not acquire lock, this means timer is running
iputs "Stopping timer"
} else {
# Acquired lock, this means that waitobject didn't exist
#
waitobject delete $wo
}
waitobject close $wo
}
return 0
}
}
# Open named spinlock
set wo [waitobject open "myprotector" "spinlock"]
if {$wo} {
# Spinlock open, wait - max 1spin (if lock can't be instantly acquired, timer already exists)
if {[waitobject wait $wo 0] == 0} {
# Acquired lock
iputs "Setting up new timer!"
mytimer_do $wo
} else {
# Timer is already running
iputs "Timer already running!"
}
waitobject close $wo
return 0
} else {
# Couldn't create spinlock
return 1
}
b>d>>s
11-21-2003, 01:50 PM
hmm, i put dzsbot on a timer, i havent looked at it properly yet, it musta been dropping to bottom, then executing itself again...
thanks for spinlock thingy :)
vBulletin® v3.8.11 Alpha 3, Copyright ©2000-2024, vBulletin Solutions, Inc.