Experimental:Thread Manager
Summary[edit]
The Thread Manager is a custom TouchDesigner component designed to wrap around the Threading library of Python 3.11.x.
The Thread Manager simplifies threading and task handling in TouchDesigner for Python developers. Advanced users can access the Thread Manager COMP directly using op.TDResources.ThreadManager
. Alternatively, users who want an easier learning curve can look at the Thread Manager Client, available in the Palette (ThreadManager folder). It’s a simple callback-oriented component that wraps around the Thread Manager.
⚠️ Keep in mind that users need to be cautious when using threading in TouchDesigner. As a rule of thumb don't access objects from the main TouchDesigner thread such as OPs, COMPs, Parameters, from another thread. Whether it be for writing, reading, or any other operation. This is true whether you rely on op.TDResources.ThreadManager
or on the Thread Manager Client.
Advanced developers are invited to read the Thread Manager Ext page.
Debugging of threading can be made easier using the ThreadsMonitor.
Internally and by default, the Thread Manager is creating TDThreads, Python threads (relying on the threading library) that are extended with additional features specific to TouchDesigner and the Thread Manager. The default TDThreads form a worker pool. They are consuming TDTasks, which are added to a queue where, when a TDThread is on standby, a newly added TDTask get picked and executed in a thread. The TDTask is a custom object, that can be instantiated by advanced users where target methods and additional attributes can be set to customize the execution of the TDTask in a TDThread.
💡With the Thread Manager being part of our TDResources, it is recommended to read and interact with parameters using the ThreadsMonitor.
Parameters - Thread Manager Page
Runningthreads
- The number of threads currently running and registered on the Thread Manager.
Numberofworkers
- The number of worker threads currently running and registered on this ThreadManager.
Maxnumberofworkers
- The maximum number of worker threads that are making the pool. Cannot be greater than Max Number Of Threads (or os.cpu_count()). Default to 4.
Maxnumberofthreads
- Total maximum number of logical threads on this hardware. The workers pool cannot be greater than this value. Its value is equal to os.cpu_count(). When this value is reached, additional standalone threads will follow the fallback strategy selected.
Strategyonmaxthreadsreached
- ⊞ - When the maximum number of threads is reached, pick a fallback strategy.
- Queue
Queue
- Create a task to be enqueued for postponed execution, once a worker thread is freed or the current number of threads gets smaller than os.cpu_count().
- Except
Except
- Raise an exception.
- Create
Create
- Create a thread to force immediate execution.
Tasksinqueue
- The number of TDTasks currently in the queue for execution by the workers pool.
Totaltasks
- The total number of TDTasks that are currently running or in queue.
Queuemaxsize
- The maximum size of the TDTasks queue. 0 means that there is no limit.
Terminateallthreads
- Terminate all the currently running TDThreads. Use with caution and for debugging purposes. Implement an event or raise an exception on a TDThread individually otherwise.
Reset
- Reset the ThreadManager to its initial state, post initialization. Shutdown all running threads and restart workers pool. Clear all running and pending TDTasks.
Utilities
- Extras shipping with the Thread Manager COMP.
Openlogger
- Open the internal Logger COMP parameters dialog.
Parameters - About Page
Help
-
Version
-
Toxsavebuild
-
TouchDesigner Build:
Palette |
---|
• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • |