Using a lambda function for invokeLater and invokeAsynchronous

Hello! Im trying to use a lambda function as a parameter to invokeLater and invokeAsynchronous. My code looks like this:

def executeWArgsAsync(funcName, *args, **kwargs):
	return system.util.invokeAsynchronous(lambda: funcName(*args,**kwargs))

The function executeWArgsAsync must run invokeAsynchronous with any function that I pass as a parameter to it.

Is there any problem expected to happen using this approach?

What version of Ignition are you using? system.util.invokeAsynchronous already supports passing args and kwargs in, and will transparently pass them to the inner function. So, I'm not sure what this wrapper function is adding unless you're on an older version lacking that support.

As for your question, it should work fine. You might consider using functools.partial to be more explicit about what you're doing, but they should be basically equivalent, functionally.

Im using 8.1.

So I should be able to use system.util.invokeAsynchronous(funcName(*args, **kwargs))?

Per the manual it should be system.util.invokAsynchronous(func, *args, **kwargs)

1 Like

Pass your positional args in a sequence (list, tuple) and your named arguments in a mapping (dictionary). Handle them as normal args in your function.

2 Likes