# Continuously running script

**URL:** <https://forum.inductiveautomation.com/t/continuously-running-script/1747>\
**Category:** Ignition\
**Created:** [April 9, 2010, 9:30pm UTC](https://forum.inductiveautomation.com/t/continuously-running-script/1747 "2010-04-09T21:30:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Automate](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@Automate](https://forum.inductiveautomation.com/u/Automate)\
**Post date:** [April 9, 2010, 9:30pm UTC](https://forum.inductiveautomation.com/t/continuously-running-script/1747/1 "2010-04-09T21:30:40Z")

</div>

The discussion in this post [http://www.inductiveautomation.com/forum/viewtopic.php?p=11906#p11906](http://www.inductiveautomation.com/forum/viewtopic.php?p=11906#p11906) about problems of high CPU usage if you had a continuously looping script got me thinking. What if the loop has a sleep statement so it does not tie up the CPU.

So I placed the following code in a Gateway start-up script:

[code]import system  
import time

while 1:  
#Do some tasks  
system.file.writeFile(“C:\Mydebug.txt”, time.strftime(’%x %X’) + ‘\r\n’, 1)  
time.sleep(60)[/code]

It does run in its own thread and because of the sleep, the CPU usage is low. But it does cause some other problems. With the script running I can not make any edits to any Gateway script in Designer. I just get a timeout when I try to save. I also could not restart the Gateway. The only easy way I found to get out of this situation was to make the Mydebug.txt file read-only so that the script would error out and stop. Then everything was back to normal.

I know you can’t protect from every type of scripting error but getting into a continuous loop is a fairly common type of programming problem.

Also, since the module API is not available someone might want to make a socket connection and keep it open in a continuously running script.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [April 10, 2010, 4:40pm UTC](https://forum.inductiveautomation.com/t/continuously-running-script/1747/2 "2010-04-10T16:40:27Z")

</div>

This is why we have timer scripts available in both the client and gateway scopes - so that we can implement the timing part correctly so that you don’t have to.
