So I’ve spawned a thread in touchdesigner to try and run a script in and despite all this the ui still hangs when I run the script…how exactly does this work in touchdesigner?
post edited : don’t use the threading stuff
Actually when I think about it, couldn’t the run command just utilize this? Is there a reason that things have to hang?
Just saw this, I’m accessing ops from another thread and it’s working fine, is there a reason? I’m just clearing and inserting values into a table
You run into the risk that the TouchDesigner thread (or other threads you launch) were in the process of modifying/accessing the OP when your thread changes the OP.
In the future we may implement a locking mechanism, but currently your thread is very unsafe.
If I don’t have another op accessing, so for example I’m just clearing and populating a Table DAT would that be a risk? As it’s kind of the same as editing a DAT in a text editor…I can understand it’d be a nightmare in a script SOP or something though.
Yes, you’ll likely end up crashing the process. Also even if you aren’t doing anything to the OP, it doesn’t mean our code isn’t doing something to it’s memory.
Righto that’s good to know, I’ll stick to using two different touch instances then, would be nice to have this though.
I’ll remove the above code so people don’t break it
Just use queue objects and you can do it in one TD instance. There’s a multithread / queue example on the forums
Doesn’t that still open up another thread that would still be accessing the operator?
it takes care of the possible crashes malcolm mentioned. so you can create a thread, use the queue to give the thread some TD data to work on, and have the thread write into another queue that then can be accessed from any TD node. Isn’t that what you are trying to achieve?
The way I understand it, threading in python will still run on the same core your TD main thread uses, hence any complex work you do in your threads will impact performance. Think we have to use multiprocessing for optimal performance
Yeah the complex work is just pulling tweets from twitter, currently theres a hang of about half a second whilst the data is pulled from their api. If a queue will speed that up without crashing touch then it’d be spot on.
I’m using a Python thread to do background logging over HTTP e.g. hit a url when a user presses a button or takes some other action. Nice since using liburl blocks until the request is finished. Seems to be working well. There is no access to OP data inside the thread so that’s not an issue.