Experimental:Thread Manager

From Derivative
Jump to navigation Jump to search

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.

PythonIcon.pngthreadManager Ext


Parameters - Thread Manager Page

Running Threads Runningthreads - The number of threads currently running and registered on the Thread Manager.

Number Of Workers Numberofworkers - The number of worker threads currently running and registered on this ThreadManager.

Max Number Of Workers 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.

Max Number Of Threads 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.

Strategy on max threads reached 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.
Tasks In Queue Tasksinqueue - The number of TDTasks currently in the queue for execution by the workers pool.

Total tasks Totaltasks - The total number of TDTasks that are currently running or in queue.

Queue Max Size Queuemaxsize - The maximum size of the TDTasks queue. 0 means that there is no limit.

Terminate All Threads 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 - Reset the ThreadManager to its initial state, post initialization. Shutdown all running threads and restart workers pool. Clear all running and pending TDTasks.

Utilities Utilities - Extras shipping with the Thread Manager COMP.

Open Logger Openlogger - Open the internal Logger COMP parameters dialog.


Parameters - About Page

Help Help -

Version Version -

.tox Save Build Toxsavebuild -

TouchDesigner Build:

Palette
Palette • Palette:arcBallCamera • Palette:arcBallGeometry • Palette:audioAnalysis • Palette:audioSet • Palette:battery • Palette:bitwigClip • Palette:bitwigClipSlot • Palette:bitwigDeviceRemotes • Palette:bitwigMain • Palette:bitwigNote • Palette:bitwigProjectRemotes • Palette:bitwigRemotesDevice • Palette:bitwigRemotesProject • Palette:bitwigRemotesTrack • Palette:bitwigSelect • Palette:bitwigSong • Palette:bitwigTrack • Palette:bitwigTrackRemotes • Palette:blendModes • Palette:bloom • Palette:camera • Palette:cameraBrowser • Palette:cameraViewport • Palette:camSchnappr • Palette:changeColor • Palette:changeToColor • Palette:checker • Palette:chromaKey • Palette:colorThreshold • Palette:compareComp • Palette:convolve • Palette:cornerPinSOP • Palette:cppParsTemplateGen • Palette:customAttributes • Palette:debugControl • Palette:dent • Palette:depthExtract • Palette:dilate • Palette:encoder • Palette:equalizer • Palette:feedback • Palette:feedbackEdge • Palette:firmata • Palette:gal • Palette:geoPanel • Palette:gestureCapture • Palette:graphPlot • Palette:histogram • Palette:hsvBlur • Palette:imageSearch • Palette:julia • Palette:kantanMapper • Palette:kinectCalibration • Palette:kinectPointcloud • Palette:leapPaint • Palette:lightTunnel • Palette:logger • Experimental:Palette:logger • Palette:mandelbrot • Palette:materialDesignIcons • Palette:mesh • Palette:monochrome • Palette:motionSense • Palette:movieEngine • Palette:moviePlayer • Palette:moviePlaylist • Palette:multiLevel • Palette:multiMix • Palette:noise • Palette:onScreenKeyboard • Palette:operatorPath • Palette:opticalFlow • Palette:pixelate • Palette:pixelRelocator • Palette:pointGenerator • Palette:pointillize • Palette:pointMerge • Palette:pointRender • Palette:pointRepack • Palette:pointTransform • Palette:pointWeight • Palette:popDialog • Experimental:Palette:popDialog • Palette:probe • Palette:projectorBlend • Palette:pushPins • Palette:puzzle • Palette:quadReproject • Palette:radialBlur • Palette:recorder • Palette:remotePanel • Palette:rgbaBlur • Palette:rgbaDelay • Palette:rgbContrast • Palette:sceneChanger • Palette:search • Palette:searchReplace • Palette:sharpen • Palette:sickEngine • Palette:signalingClient • Palette:signalingServer • Palette:softenAlpha • Palette:solarize • Palette:sopRender • Palette:splitter • Palette:stitcher • Palette:stoner • Palette:superFormula • Palette:SVG • Palette:sweetSpot • Palette:sweetSpotPreviz • Palette:synchroCache • Palette:synchroClient • Palette:synchroFrameIn • Palette:synchroFrameOut • Palette:synchroNDIIn • Palette:synchroSDIIn • Palette:synchroVideoOut • Palette:tdBitwigPackage • Palette:TDVR • Palette:testGrid • Experimental:Palette:threadManagerClient • Experimental:Palette:threadsMonitor • Palette:transitMap • Palette:twirl • Palette:vectorScope • Palette:virtualFile • Palette:waveformMonitor • Palette:webBrowser • Palette:webRTC • Palette:webRTCPanel • Palette:webRTCPanelRcv • Palette:xyScope • Experimental:Thread Manager