I’m using my UR10e to lift parts in and out of a electroplating tank. I use Thread_1 to calculate the remaining time and display this to the user in the variables on the run tab when the program is running. I have located the problem down to one line in a script. The line that sets the variable Time_Remaining causes an error that says Thread_1 is using too much time. When I comment out this line in the script with a hash, it runs fine. I have gone through all the forums detailing this issue and I’ve followed the advice about adding sync()'s but this does not seem to help. Anybody have ideas? I wonder if the issue is to do with the to_str function? If so, can anybody suggest a better way to display the time remaining to the user during a program run?
Just put another line at the end of your thread that says “sync()” and you should be good to go. I tend to put a sync() at the end of all my threads for this reason. Make sure it’s not being up after the “end” lines or else it won’t be helpful. Other than that, I’m not sure if you can “add” strings like that. They have a str_cat() command to append strings together. Maybe you’d have more luck with that.
The other reason your syncs may not be doing anything for you is that they would need to be present in any long-running process. Your script that you’re showing there has a WHILE loop without a sync. I tend to add syncs to any loops that are contained inside the thread as well. Othewise your WHILE LOOP could be consuming all that time before it ever hits the sync() at the bottom of your switch case.
You need to add either a sleep() or sync() inside your while loop. Usually sync() works well at the end, but as said by @eric.feldmann you need it inside long-running processes too.
If your thread is not critical, and it is just waiting, I would use a bigger wait time, such as sleep(0.1) inside the loop, so the CPU usage is as low as possible, specially if you plan to add more threads.
Thank you. This worked. I ended up changing the while to an if statement because I realised the thread loops continuously anyway, this allowed it to exit the script and reach the sync at the end of the thread.