# Error running function from system.util.invokeAsynchronous

**URL:** <https://forum.inductiveautomation.com/t/error-running-function-from-system-util-invokeasynchronous/26973>\
**Category:** Ignition\
**Created:** [July 29, 2019, 11:37pm UTC](https://forum.inductiveautomation.com/t/error-running-function-from-system-util-invokeasynchronous/26973 "2019-07-29T23:37:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [July 29, 2019, 11:37pm UTC](https://forum.inductiveautomation.com/t/error-running-function-from-system-util-invokeasynchronous/26973/1 "2019-07-29T23:37:20Z")

</div>

Hello,

I’m a bit lost as to where this error is coming from. Seems like the invokeAsync is not liking something.

Thanks in advance!

```auto
INFO | jvm 1 | 2019/07/29 14:03:03 | E [c.i.i.c.s.b.SystemUtilities] [22:03:03]: Error running function from system.util.invokeAsynchronous 
INFO | jvm 1 | 2019/07/29 14:03:03 | com.inductiveautomation.ignition.common.script.JythonExecException: TypeError: 'NoneType' object is not callable
INFO | jvm 1 | 2019/07/29 14:03:03 | 
INFO | jvm 1 | 2019/07/29 14:03:03 | at org.python.core.Py.TypeError(Py.java:235)
INFO | jvm 1 | 2019/07/29 14:03:03 | at org.python.core.PyObject. __call__ (PyObject.java:316)
INFO | jvm 1 | 2019/07/29 14:03:03 | at org.python.core.PyObject. __call__ (PyObject.java:357)
INFO | jvm 1 | 2019/07/29 14:03:03 | at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:647)
INFO | jvm 1 | 2019/07/29 14:03:03 | at com.inductiveautomation.ignition.gateway.script.GatewaySystemUtilities$1.run(GatewaySystemUtilities.java:69)
INFO | jvm 1 | 2019/07/29 14:03:03 | at java.lang.Thread.run(Unknown Source)
INFO | jvm 1 | 2019/07/29 14:03:03 | Caused by: org.python.core.PyException: TypeError: 'NoneType' object is not callable
INFO | jvm 1 | 2019/07/29 14:03:03 | 
INFO | jvm 1 | 2019/07/29 14:03:03 | ... 6 common frames omitted

```

---

<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:** [July 29, 2019, 11:48pm UTC](https://forum.inductiveautomation.com/t/error-running-function-from-system-util-invokeasynchronous/26973/2 "2019-07-29T23:48:30Z")

</div>

Can you post your code? You’re trying to run something that evaluates to null; it’s probably just a scoping issue.

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [July 30, 2019, 12:04am UTC](https://forum.inductiveautomation.com/t/error-running-function-from-system-util-invokeasynchronous/26973/3 "2019-07-30T00:04:23Z")

</div>

I suspect it’s coming from a Gateway Timer Script?

---

<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:** [July 30, 2019, 3:13pm UTC](https://forum.inductiveautomation.com/t/error-running-function-from-system-util-invokeasynchronous/26973/4 "2019-07-30T15:13:35Z")

</div>

By nature of invokeAsynchronous, it’s impossible to tell - all that stack trace is telling you is that there’s some issue with an attempt to invoke an asynch thread - specifically, the object being passed into `system.util.invokeAsynchronous` is null.

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [July 30, 2019, 6:00pm UTC](https://forum.inductiveautomation.com/t/error-running-function-from-system-util-invokeasynchronous/26973/5 "2019-07-30T18:00:25Z")

</div>

The end goal of this is to provide a summary of process activity after some period (overnight, weekly, etc.) so it was sending out an email for each process change. Possibly the whole thing should be re-worked to send only one email with a summary of all changes...

I got rid of the invokeAsynch. I was thinking the executeAndDistribute might need it to send multiple emails in a loop... Not sure.

The _sendEmail_ function and new code (i.e. invokeAsynch) are within a _for_ loop as mentioned in the post. Iterating through a SQL table for tank numbers & info.

```auto
for n in range(len(pyTankDS)):
    tankNo = pyTankDS[n][0]
	tank = 'Tank ' + tankNo

	#read relevant properties from tag path
	volume = str(round(system.tag.read('[default]Tank Status History/'+tank+'/Volume').value,1))
	
    def sendEmail(tankNo=tankNo, tank = tank, volume = volume):	
    	import system
    	recipients=["jane@test.com","jon@xyz.com"] #
	    system.report.executeAndDistribute(path="xyz", parameters = {"tankNumber":tankNo}, project="xyz", action= "email", actionSettings = {"to":recipients, "smtpServerName":"Mail Server", "from":"jon@xyz.com", "subject":tank + 'test email', "body":tank + " test " + volume})
    system.util.invokeAsynchronous(sendEmail)

print 'post-email function'
system.db.runUpdateQuery('DELETE FROM tank_fills')

```

Changed to:

```auto
for n in range(len(pyTankDS)):
    tankNo = pyTankDS[n][0]
	tank = 'Tank ' + tankNo

	#read relevant properties from tag path
	volume = str(round(system.tag.read('[default]Tank Status History/'+tank+'/Volume').value,1))

    recipients=["jane@test.com","jon@xyz.com"] 
    system.report.executeAndDistribute(path="xyz", parameters = {"tankNumber":tankNo}, project="xyz", action= "email", actionSettings = {"to":recipients, "smtpServerName":"Mail Server", "from":"jon@xyz.com", "subject":tank + 'test email', "body":tank + " test " + volume})

print 'post-email function'
system.db.runUpdateQuery('DELETE FROM tank_fills')

```

More info on this thread:

> [@Waiting for certain time to send email with executeAndDistribute](http://forum.inductiveautomation.com/t/waiting-for-certain-time-to-send-email-with-executeanddistribute/26448/4):
>
> The emails seem to be sending now, but there is an INDENT EOF error occurring after the script runs. I’m not sure if this is a cause for concern or how to prevent the error. FWIW, this code is in a Gateway Event Timer Script contained within a for loop. def sendEmail(tankNo=tankNo, tank = tank): import system recipients=["jane@test.com","jon@xyz.com"] # system.report.executeAndDistribute(path="xyz", parameters = {"tankNumber":tankNo}, project="xyz", action= "email", actionSetti…

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [July 31, 2019, 1:34am UTC](https://forum.inductiveautomation.com/t/error-running-function-from-system-util-invokeasynchronous/26973/6 "2019-07-31T01:34:54Z")

</div>

It seems the error was still coming up after I removed the invokeAsynchronous from the script.

Would it have tried to use invokeAsynchronous if it was a ‘dedicated’ thread? I switched it over to shared and will see if the error goes away.

Otherwise, I don’t see any other code that uses invokeAsynchronous. Maybe there is a scoping option somewhere else that has an invokeAsynchronous option, like an event script or such?

Thanks,

Michael
