# URScript with program with thread

**URL:** <https://forum.universal-robots.com/t/urscript-with-program-with-thread/25682>\
**Category:** Technical Questions\
**Created:** [December 14, 2022, 2:28pm UTC](https://forum.universal-robots.com/t/urscript-with-program-with-thread/25682 "2022-12-14T14:28:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PMonforte](https://avatars.discourse-cdn.com/v4/letter/p/e36b37/32.png) [@PMonforte](https://forum.universal-robots.com/u/PMonforte)\
**Post date:** [December 14, 2022, 2:28pm UTC](https://forum.universal-robots.com/t/urscript-with-program-with-thread/25682/1 "2022-12-14T14:28:10Z")

</div>

Greetings URCommunity  
I’m having some issues writing a script with a thread in it. I am sending the script via TCP/IP through port 30003  
Here is the program:  
def Prog():  
global var = False  
set\_standard\_digital\_out(4, True)  
set\_standard\_digital\_out(5, True)  
sleep(1)  
movep(…)  
movep(…)  
var = True  
movep(…)  
movep(…)  
halt  
end

Here is the thread:  
thread myThread():  
while (var == False):  
sleep(0.01)  
end  
set\_standard\_digital\_out(7, True)  
while(get\_standard\_digital\_in(1) == False):  
sleep(0.01)  
end  
end

I think the reason why I need the thread is evident. If I place a while loop between waypoints, the robot is going to stop in between and I want it to keep moving. Thus, the thread is vital.  
I have typed this on the teach pendant and had no problem. I haven’t managed to get it to work via URscript  
Any help is much appreciated,  
Best regards,  
Pedro Monforte

---

<div class="post-metadata">

**Author:** ![Alejandro.GS](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@Alejandro.GS](https://forum.universal-robots.com/u/Alejandro.GS)\
**Post date:** [December 14, 2022, 3:01pm UTC](https://forum.universal-robots.com/t/urscript-with-program-with-thread/25682/2 "2022-12-14T15:01:08Z")

</div>

Continuing the discussion from [URScript with program with thread](https://forum.universal-robots.com/t/urscript-with-program-with-thread/25682):

Hi Pedro,  
If you’ve write your code in the teach pendant and it works, you can open the .script generated and see what is doing that you are missing.

I think that you need to initialize you thread with a command like this  
_thread01 = run myThread()_

that line must be outside the thread. It is posible to halt threads or kill, you can find this information in the scriptmanual
