Touchdesigner and PM2


Starting a general discussion about TouchDesigner and PM2 ( For process managing in installations, it seems like a very viable, robust tool. I’ve been working through some initial tests, and wanted to report some findings (all Windows, no Mac testing).

My first stumbling block was figuring out how to get Touchdesigner to be “visible” on launch. Running this:

pm2 start "C:\Program Files\Derivative\TouchDesigner\bin\TouchDesigner.exe" -- "C:\00-running-td-with-pm2\test.toe"

will launch TD, but it will be “invisible”. Try it and see what I mean (it’s in Task Manager, under background processes). After much wrangling, I found this parameter, which can be used in the ecosystem.config.js approach, or using the javascript API approach:

windowsHide: false

This works, launching TD normally. Okay that’s awesome.

Wouldn’t it be great if we could use regular old print() to generate logs! Well, this is where I’m currently stuck. So- if you manage a simple python app with PM2:

import time
while 1:
    print("Start: %s" % time.ctime())

You’ll get the print stdout in pm2 monit- and then you can easily route that to a file using output: "PYtest.log" (and use all the other tools provided by PM2, like auto-rotating logs, etc. It’s great, reduces complexity of the application, logs are streamed / stored wherever you want.

But with TD, stdout is tricky. You can use approaches that route stdout to a DAT, which is then saved, and you can access them via PM2 (using pm2 logs TDtest), but I can’t figure out an elegant way to get them using pm2 monit. See or search the forum for “stdout” or “logs” for other approaches.

Anyways, just wanted to start a conversation. If anyone wants to see some sample code or other notes, just keep this thread moving :slight_smile:

Hey @gardyll

Thanks for sharing your experience with PM2. It is indeed a great process management tool.

I didn’t use it in a while but I will try to get something up and running locally and give this a go in the coming month.

Did you try to have a look with the Python logging library, from within TD ? You could output some log files and use tail to see them update in a terminal in real-time whenever something is pushed to it.

When using pm2 monit does it work only for currently running subprocesses making use of stdout ?

The Python logging lib allows to log with a bunch of handlers:

The one that you might be after is logging.handlers — Logging handlers — Python 3.11.2 documentation


Have you tried using the Python logging library in TD? I haven’t gotten much luck, keep getting errors… When I try:

import logging
logging.root.setLevel(logging.INFO)'test message')

I get

td.tdError: INFO:root:test message
Results of run operation resulted in exception.

But it works in Python.

When using pm2 monit does it work only for currently running subprocesses making use of stdout ?

Yes, this is my understanding, and can confirm- if you run tdu.forceCrash() you’ll see:

But you won’t see print() output. Continuing my investigations…

Where are you getting this ? It works pretty well in textport ?


Interesting- I was trying to run it via a text DAT. Yes, running in the Textport does work. I’m using 2022.31030 BTW.

But these messages (even logging.error('test error')) don’t make their way to pm2 monit or pm2 logs TDtest for that matter.

Ok, I can reproduce thanks. I will look into it with a dev.

Yes, I have logged this to be discussed internally. We know what is causing the limitation but it has some complicated internal ties

Thanks for the report.


Yes, I imagine the complication arises with tdutils.outputcatcher.StdoutCatcher, and it’s role in controlling sys.stdout in TD. It would be very interesting if there was a way to redirect to “normal” sys.stdout via flag in TD’s settings.

Maybe a settings feature that allows print() to be directed to both the Textport and “normal” sys.stdout…

Thanks very much for thinking about this. I’ve seen some chatter on Discord that suggests a tighter integration with a process manager like PM2 could greatly benefit those of us doing permanent installations.