# Timer and Function

**URL:** <https://forum.inductiveautomation.com/t/timer-and-function/20384>\
**Category:** Ignition\
**Created:** [October 25, 2018, 8:21pm UTC](https://forum.inductiveautomation.com/t/timer-and-function/20384 "2018-10-25T20:21:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [October 25, 2018, 8:21pm UTC](https://forum.inductiveautomation.com/t/timer-and-function/20384/1 "2018-10-25T20:21:52Z")

</div>

Hello Everyone,

I am trying to trigger a function call every 1 second to see if the file in directory exists.  
The code works fine when there is a file but didn’t seems to be working when there isn’t a file and gives

“RuntimeError: maximum recursion depth exceeded” and then  
at org.python.core.Py.RuntimeError(Py.java:152)  
at org.python.core.Py.JavaError(Py.java:490)  
at org.python.core.PyTableCode.call(PyTableCode.java:168)  
at org.python.core.PyBaseCode.call(PyBaseCode.java:120)  
at org.python.core.PyFunction. **call** (PyFunction.java:307)  
at org.python.pycode.\_pyx183.ReadFile$2(module:project.Reading\_File:16)  
at org.python.pycode.\_pyx183.call\_function(module:project.Reading\_File)  
at org.python.core.PyTableCode.call(PyTableCode.java:165)" repeatedly.

The code I have is,  
import time  
from threading import Timer  
import os

**def timerFunc():**  
t = Timer(1000.0, ReadFile()).start()  
system.gui.messageBox(“Waiting”)

**def ReadFile()**:  
contents = “C:\Users\kshah2\Desktop\file.asc”  
**if system.file.fileExists(contents):**  
File = system.file.readFileAsString(contents)  
window = system.gui.getWindow(‘carlos’)   
window.getRootContainer().getComponent(“Text Area”).text = File  
**else:**  
timerFunc()

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [October 25, 2018, 8:33pm UTC](https://forum.inductiveautomation.com/t/timer-and-function/20384/2 "2018-10-25T20:33:57Z")

</div>

Hmm. I’m not sure if this will truly solve your problem, but I believe how it is right now you are actually just calling ReadFile(), not passing it. So it hasn’t even made the timer yet, just running that function. Try

```auto
t = Timer(1000.0, ReadFile).start()

```

instead.

BTW, use three backticks, ```, above and below the code you paste and it will look much nicer.

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [October 25, 2018, 8:55pm UTC](https://forum.inductiveautomation.com/t/timer-and-function/20384/3 "2018-10-25T20:55:47Z")

</div>

Hi… Thank you so much.  
Worked…  
Yeah, sorry about that it’ just I am new in Forum and didn’t quite knew how can I do that.

Thanks again.
