I found many threads in the forum for discussion on sleep(). Though I know this is not recommended to use, In my existing project there were several places sleep() has been used. So I want to get rid of this and looking for alternative. Which would be the best alternate approach?
I found that in the manual “If a sleep() or While Loop function must be used, then they should be called from system.util.invokeAsynchronous to prevent blocking any other scripts.” Sincesystem.util.invokeLater is not supported in Perspective.
How to use this for my case?
Unlike Vision, Perspective is fairly tolerant of short sleeps (not in a loop). We need to know how it is used by your application to know how to help you, if even necessary.
You probably want to use CSS for this. What exactly are you trying to do?
If I’m understanding correctly, it looks like you’re running code to reset the rotation on something every second. that would definitely cause performance issues to do it that way.
To clarify the use case, actually we are showing a load Icon while changing the view in the Display.
def runAction(self):
Import time
if self.session.custom.Anim == True:
while self.session.custom.Anim == True:
for degree in range(0, 2000, 10):
self.getChild("root").getChild("Icon").props.style.transform = 'rotate(' + str(degree) + 'deg)'
time.sleep(0.25)
if self.session.custom.Anim == False:
break
if self.session.custom.Anim == False:
break
On each view change we are enabling and disabling the custom property. This has been implemented previously. So just want to understand this will cause any performance issue? Shall we use system.util.invokeAsynchronous instead time.sleep? In thread Dashboard we are seeing multiple process is in state of Timed Waiting and Waiting. So we need to understand what is causing the below status…
I see you've made another post related to trying to determine what all the threads are doing. Are you experiencing a log of performance problems or something? Are these related?
That is an unbounded loop. You should never use those in Ignition event scripts, whether using .sleep() or not. Event scripts should run to completion in a repeatable duration, preferably in a handful of milliseconds.
Any longer delays should be handled by reacting to property changes as data flows in your UI, or by including polling bindings with associated scripts, perhaps in gateway timer events.
If you have a process that is heavily sequential, and you can prevent repeat launches while a prior is running, then invokeAsynchronous might be appropriate.