Greetings! I’m new to TouchDesigner but I’m an experienced programmer. I’ve started using a technique for long operations in python and I’d like to know if it seems reasonable in a TD context, or if there are better or more standard ways of doing things.
For this application, I have to communicate with three HTTP APIs (including sending files) and use a number of command line programs (a slew of small utilities to control a Fastec camera, and ffmpeg to assemble the camera’s output frames into an h264 video file). My general approach so far has been to kick off work in a threading.Thread, then use a Timer CHOP to poll for a result. I use a threading.Lock for memory safety.
For the HTTP stuff, this seems to work fine. The use case is pretty simple – make a sequence of requests in python, and at the end, make sure things turn out OK. I’m using the requests module and write “synchronous” code that then wrapped in a thread.
I’m doing something similar with the command-line tools, but I use the subprocess module. The ffmpeg code should be very similar to the http/requests code. The camera controls are a bit more complex, so I’m using a queue.Queue (which is conveniently synchronized) to pass command and response objects. A Timer CHOP calls a poll method that pops things off the queue and reacts accordingly.
How does this sound to experienced TouchDesigner users? I think I’m not doing too much work in the threads, mostly waiting, so consuming the GIL shouldn’t be a problem. I do worry about error handling, especially as a TD newbie, but I’m trying to fix that with my schedule – freeze features early and test for a couple weeks. And ask for help early!!
Are there other common approaches to performing long tasks in TD without impacting the frame rate? Could I be doing more, or less, with python vs TD native operators?
I’ve considered wrapping the functionality of the camera’s command-line tools in a DLL with the CPlusPlus op – is this advisable over using pipes in python?
Many thanks in advance for any help with my vague questions :]