Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
WatchDog Thread
#3
Everytime i waste your time Gintaras, i feal i should payback by contributing to the knowledge base. So Ill post this code in case anyone is intrested

WatchDog Timer

Everytime I start the application to scrape from, I also start the watchDog Thread

;; a few global variables
int+ watchDogCountDown
int+ watchDogLimit
int+ watchExec_handle

;; setup and run the thread
watchDogLimit = 60*5
watchDog_reset()
watchExec_handle = run("long_running_application_name.exe")
mac "watchDogThread"

--------------

function watchDog_reset

watchDogCountDown = watchDogLimit

--------------

function watchDogThread

rep
,watchDogCountDown - 1
,if(watchDogCountDown < 10) out "watchDog=%d" watchDogCountDown
,wait 1.0
,if(watchDogCountDown = 0)
,,clo watchExec_handle
,,err+
,,,out "watchDogStopped"
,,,ret
,,out "watchDogStopped"
,,ret


--------------------------------

In main loop of the scraping program put this

watchDog_reset()

This sets count down value to a high number and prevents the system from killing the program.

But if the program ever hangs the watchDog will wait for 5 min and close the program with

clo watchExec_handle

Gintras, QM is great stuff!!! I was a bit taken aback by the entire change in paradyme but now Im a believer.... It remindes me of an environemnt i worked with years ago called "forth". The environment yes, the language no. Once again, great contributuion. Thanks Gintras...


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)