My project is started automatically when all the computers boot on schedule (BIOS wakeup) and shutdown based on a Windows scheduler task.
This works fine but I would like for TD to turn off all the lights before exiting. I’ve tried setting all values sent to the DMX out CHOP to zero in an execute DAT’s onExit() but it looks like this doesn’t have time to execute before TD exits.
How can I squeeze a few quick changes within the onExit() before TD quits?
Wrap you quit call in another function, then delay the call to quit TouchDesigner.
Something like
def close_project():
print("closing td")
house_keeping()
run(quit_td, delayFrames=60)
def quit_td():
project.quit(force=True)
def house_keeping():
print("run all of your house keeping here")
Yes, this would work if TD was deciding when to shutdown the computer but the opposite is true in my case. Windows scheduler calls a system shutdown and the OS asks TD to quit.
Ideally I would like to keep things this way and delay TD’s shutdown while I do the housekeeping rather than have TD schedule the shutdown…
I am able to perform certain things from onExit() before TD quits however. For instance this gets executed correctly:
open('shutting down.txt, ‘a’).close()
But I don’t have enough time to clear the DMX out CHOP values before TD quits.
I thought of spawning a new process before quitting TD but the DMX out CHOP won’t exist at that point so it would need to be a separate executable or script which accesses the DMX interface which is a bit convoluted.
Maybe I could add a separate scheduler task which would tell TD to fade everything out a minute before it gets shut down by the system. What would be the simplest way to send a signal to TD from an external app/script? I’ve done OSC, TCP/UDP, ArtNET etc from Python in the past. Anything simpler than a network message I’m overlooking?
Thanks @raganmd your replies are always interesting and appreciated!
Hmm - I see. That’s trickier then. Killing a process from a CMD doesn’t give you much lead time.
Is this at a regular time every night? Like, is there any reason not to use a clock CHOP and turn off the lights at a known time at the end of the day before the scheduler runs?
That is indeed a possibility but Id’ rather have all the scheduling done from the same place. It makes things simpler/easier to maintain by someone else later.
I wonder then what can usefully be done from within the onExit() handler of the execute DAT besides writing to a file?
What about interrupting the onExit() handler midway, doing housekeeping followed by a project.quit(force=True)? I saw a post you made a couple years back on this same subject.
I’m not a huge fan of this approach, if only because it means you no way to reliably Stop TouchDesigner… if you have something that can block onExit() then you could have a condition where you could never shut down reliably.
In your situation, I’d probably do something like this.
Create a simple python script to send a close message:
I’d use that callback to do my quit procedure like outlined above.
I’d schedule that python script to run 5 minutes before a failsafe that kills TouchDesigner. That way you first attempt to gracefully exit your installation. If that fails, then you do still close TouchDesigner. The edge case here is a situation where the lights get left on for a night if the graceful exit fails.