Sign in to follow this  
Followers 0
timbCFCA

Bug in Sleep when used repeatedly

4 posts in this topic

I have a small script that I have turned into a service using the UDFs from this forum.

The service definition calls my custom function, sleeps for 1 second and then restarts my function.

While $gServiceStateRunning

CST()

; Wait 1 seconds

logPrint("Error state after CST:" & @error )

logPrint("Starting sleep...")

Sleep(1000)

logPrint("Ending sleep...")

WEnd

Things will go well for a while and then the service will simply stop responding. I wrote in some additional logging but the process, where I am getting the following:

20120203 114722 [5056] >> Starting sleep...

20120203 114723 [5056] >> Ending sleep...

20120203 114723 [5056] >> Starting CST function...

20120203 114723 [5056] >> Enumerating registry...

20120203 114723 [5056] >> Enumerating registry...

20120203 114723 [5056] >> Enumerating registry...

20120203 114723 [5056] >> Clearing error code

20120203 114723 [5056] >> Exiting loop

20120203 114723 [5056] >> Setting default group if none exists

20120203 114723 [5056] >> Reading registry data...

20120203 114723 [5056] >> Exiting CST function

20120203 114723 [5056] >> Error state after CST:0

20120203 114723 [5056] >> Starting sleep...

The hang always occurs at the starting sleep line. Should I look at another timing function?

Share this post


Link to post
Share on other sites



I'm a lot more suspicious about the logPrint function. Could you post it here, or show us where you got it?

Share this post


Link to post
Share on other sites

I've been reading through the comments on the Services functions. That is where I got the logPrint and everything but the one block of code I put together.

Share this post


Link to post
Share on other sites

The logPrint function shouldn't cause trouble, still I'm even more sceptical of Sleep() being the culprit, seen as a huge amount of scripts call sleep 100 times per second and they're usually fine.

I suspect there is some some sort of event constantly calling a function, but without more code it's impossible to tell.

It'd help if you could post a working example that demonstrates the problem, or at least as much as you can as the code you posted doesn't give any clues.

I will probably be unable to reply soon, but maybe someone else will get an idea.

There are two things you can do to give a little more information on the problem:

replace Sleep() with:

$iTimer = TimerInit()
Do
Until TimerDiff($iTimer) > 1000

This will bump your CPU usage to 100% (for one logical core at least), so it's not meant as a solution, but it'll be interesting to see if it makes a difference.

Go to the Tools menu in Scite4AutoIt and click "Trace: Add Func Trace Lines" in both your main script and any includes used. (Don't forget to save each one after you add the trace lines)

Run the script and check the console when it becomes unresponsive.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0