python API - detect shutdown
- djdelorie
- Away
- Senior Member
-
Less
More
- Posts: 68
- Thank you received: 10
04 Jul 2026 16:45 #347521
by djdelorie
python API - detect shutdown was created by djdelorie
I've seen a couple of "solutions" to this, but my question here is: what's the canonical way to detect that linuxcnc is shutting down and/or exiting, or isn't running, using the python linuxcnc.stat.poll() api ? I can start my python script in hal using loadusr, but there's no unloadusr, and I can't just run it at computer boot because linuxcnc.stat() just fails if linuxcnc isn't running yet. I tried using the parent PID but that isn't reliable (and prevents you from manually running the script in the background)
I've attached my script. I'd like to cleanly detect that linuxcnc has exited or the computer is shutting down, and send a final MQTT message to home assistant to update the status to "off".
I've attached my script. I'd like to cleanly detect that linuxcnc has exited or the computer is shutting down, and send a final MQTT message to home assistant to update the status to "off".
Please Log in or Create an account to join the conversation.
- rodw
-
- Offline
- Platinum Member
-
Less
More
- Posts: 11976
- Thank you received: 4080
05 Jul 2026 05:13 #347526
by rodw
Replied by rodw on topic python API - detect shutdown
I trying to hook up with a guy in an unfriendly timezone (for an Aussie) who has been working on a implementation of the MTconnect protocol for Linuxcnc that does exactly what you want. The cool thing is that it supports MQTT and there are already integrations to Home Assistant if you have a Fanuc machine. Right now, I don't know any more detail but keep an eye on my @MrRodW YouTube channel as I will cover it there. Once we get going, I'm sure another like minded helper won't go astray.
Please Log in or Create an account to join the conversation.
Time to create page: 0.399 seconds