Multiple logger threads spawned when using invokeAsynchronous

I've noticed when using invoke asynchronous to run some long running functions, that sometimes when using inside said functions causes the same message to be printed multiple times, on different threads.

This is a bit confusing, as I'm not sure if the code is actually executing things multiple times, or if its just the logger messaging that is being doubled up.
For debugging, I'd want to be sure one way or another what is going on.

What is actually causing this, and is there a way to prevent it?

Ideally I'd want to be able to print out logger messages in the order they execute in the asynchronous function call, and only print once per call to the logger.

I would think you are running multiple threads and duplicating the work. If you don't wan't parallel actions, you need to block new threads when old ones are running. And/or ensure all global or module-global variables are protected with mutexes.


Thanks for the response.
How would we know that we are running multiple threads though?

For more context, the scripts are being triggered in the root container "property change" event handlers.
But they were conditioned to only run if an "inputsChanged" property was true, which should only have been true once

Ahhhh so my last comment got me thinking, and i had a bit of dodgy logic in my propertyChange event handler, which meant the "long running process" function must have been called multiple times due to some of the root container properties updating and re-firing the event handler.

I have a root container property called "udpating" which is set true when processing starts, and false when it finishes.
Just needed to incorporate that into my logic checks for starting a new "process" / thread., and now things look a lot better. :+1: