I have an running python script, If I want to stop it I must reboot the CP X8. So my question is: Does the CP X8 have a command can stop the running script?
put your main code in a while condition. then change the condition variable from some external fuction.
while (global.stop == 0):
then change global.stop value from web, or other external procedure if possible.
its also possible to use socket connection as in example in http://www.digi.com/wiki/developer/index.php/TCP_to_Zigbee_Dynamic_Name_Mapping . search for “Quit socket in read list”. use the code required for ‘quit_sock’ variable, then when you telnet to your device on port 30000, script stops.
I think the question was “can I externally halt a running script in a ‘kill process’ way”.
The answer is not reliably - you’ll normally need to reboot to be 100% sure what your system status is.
Trivial single-threaded python scripts can be designed to stop themselves gracefully, however if you start spawning children-threads it quickly becomes unpredictable. Halting the main thread causes the child to become orphaned, yet continue running and occupying resources forever.
The X4/X8 products are NOT designed to be as interactive as say Windows or Linux.
yup, but for single threaded script its kinda reliable.
on a multithreaded environment, when the main script is killed, and children are present - device reboots itself anyway.
i managed to implement stages. set public.stop to i.e. stage 3, children threads stop and set to stage 2, main threads stop and set to stage 1. main program loop stops.
True - you CAN create scripts which gracefully halt.
I have multi-threaded tools where the parent traps a ‘stop request’ and loops through halting & waiting for all children to acknowledge and also gracefully exit. This is standard Python.
The problem is that if one of the ‘child threads’ (which are NOT really children but independent daemons in the bigger picture) fails to be caught or fails to halt, then you need to reboot anyway.
If (as example) one of those children opened the serial port, then until you reboot your serial port ‘is lost’. So one could spend huge amounts of false effort trying to debug why the serial port is no longer working …