# Python Timer on a tag event script

**URL:** <https://forum.inductiveautomation.com/t/python-timer-on-a-tag-event-script/19319>\
**Category:** Ignition\
**Created:** [August 19, 2018, 4:02pm UTC](https://forum.inductiveautomation.com/t/python-timer-on-a-tag-event-script/19319 "2018-08-19T16:02:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaron.shields](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@aaron.shields](https://forum.inductiveautomation.com/u/aaron.shields)\
**Post date:** [August 19, 2018, 4:02pm UTC](https://forum.inductiveautomation.com/t/python-timer-on-a-tag-event-script/19319/1 "2018-08-19T16:02:56Z")

</div>

Hi there,

I am trying to execute a script on a tag on the valueChanged event. I know that you cannot use invokeLater() as this is a client scoped function. Instead, I am trying to use a Python Timer thread.

When I put this code in the script console, it executes as expected. However, when I put this code in a tag script, it does not fire at all but throws no errors either.

```
if currentValue.value == 1:
	from threading import Timer
	def Clear():
		system.tag.write("some/tag",0)
	Timer(4.0, Clear).start()

```

The odd thing is that when I put Clear() instead of just Clear, the function fires immediately without waiting for the time specified in Timer.

Any ideas as to this behavior?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 20, 2018, 3:20pm UTC](https://forum.inductiveautomation.com/t/python-timer-on-a-tag-event-script/19319/2 "2018-08-20T15:20:30Z")

</div>

Gateway scoped scripts don’t have a default tag provider, so tag writes need to be fully qualified:  
`system.tag.write("[default]some/tag")`

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 20, 2018, 3:23pm UTC](https://forum.inductiveautomation.com/t/python-timer-on-a-tag-event-script/19319/3 "2018-08-20T15:23:59Z")

</div>

> [@aaron.shields](#):
>
> The odd thing is that when I put Clear() instead of just Clear, the function fires immediately without waiting for the time specified in Timer.

There's nothing odd about this... when you add the parenthesis you're invoking the function rather than passing a reference to it.

---

<div class="post-metadata">

**Author:** ![aaron.shields](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@aaron.shields](https://forum.inductiveautomation.com/u/aaron.shields)\
**Post date:** [August 20, 2018, 3:35pm UTC](https://forum.inductiveautomation.com/t/python-timer-on-a-tag-event-script/19319/4 "2018-08-20T15:35:50Z")

</div>

Thanks PGriffith, the fully qualified string worked correctly. Threw me off when it executed in the script console without needing that full qualification.

Hey Kevin, thanks for the response. I’m pretty new to Python. I understand that parenthesis invokes the function, but that occurs even inside of the Timer functions “Scope” (I’m not sure how to say this)… IE it ignores the parameters of Timer?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 20, 2018, 3:38pm UTC](https://forum.inductiveautomation.com/t/python-timer-on-a-tag-event-script/19319/5 "2018-08-20T15:38:47Z")

</div>

`Timer(4.0, Clear).start()`  
Is creating an instance of the Timer class with two arguments: `4.0`, and the `Clear` _function object_.  
`Timer(4.0, Clear()).start()`  
Is creating an instance of the Timer class with two arguments: `4.0`, and the _result_ of the `Clear()` function call.

Think of it as “unwrapping” each element - first `Clear()` is called, then the result is inserted into `Timer()`, then `.start()` is called.

---

<div class="post-metadata">

**Author:** ![aaron.shields](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@aaron.shields](https://forum.inductiveautomation.com/u/aaron.shields)\
**Post date:** [August 20, 2018, 3:50pm UTC](https://forum.inductiveautomation.com/t/python-timer-on-a-tag-event-script/19319/6 "2018-08-20T15:50:35Z")

</div>

Understood, thanks for the clear explanation!
