closing a child program
John Rickman (71) 646 posts |
I am writing an app, !AppA, which launches !AppB using:
When !AppA quits I want to tell !AppB to quit also. How can I do this? The apps are written in python. |
Simon Willcocks (1499) 513 posts |
Wimp applications? Couldn’t you send it a Wimp_Quit message? |
Rick Murray (539) 13840 posts |
You’d need to use some derivation of Wimp_StartTask instead of os.system in order to get the task handle of the child so you’ll know where to send the Quit message. |
John Rickman (71) 646 posts |
Wimp applications? Couldn’t you send it a Wimp_Quit message? AppA, the parent, is a Wimp app which uses the toolbox. Wimp_Quit message requires a handle. I don’t think filer_run provides one. |
David J. Ruck (33) 1635 posts |
Filer_Run is for use by Obey files, don’t use it in programs! As Rick says the correct way is to use the Wimp_StartTask SWI, and store the resulting handle so you can send it a Wimp_Quit message. |
Andrew Rawnsley (492) 1445 posts |
Another (rather more scatterfire) solution, if you happen to have ever requested a message block from Allocations, is to use your own broadcast wimp message with the name of the task to close (for example) and any other data. This has the benefit (but also downside) that multiple sub-processes can be closed with one message (if passed on) rather than one at a time, but you need to handle the “die now” message in the client app too. I use this approach in a couple of programs to ensure that only one copy can run (because having several running would be counter_productive) or where multiple spawned sub-tasks could exist. This method also has the benefit of letting you do a bit more in the handler if you need to, rather than just die. Alternatively (but again, potentially problematic if you have multiple AppA running) you can use taskmanager_enumeratetasks to read the details of all processes to determine the handle of any matching child processes, and (armed with the task handle), send the quit message. Edit – but Druck’s description is simplest/best. :) |
John Rickman (71) 646 posts |
Thanks for the help every one.
The !raffle app launches successfully in a RISC OS style window but the output of the print statement is: handle: none I don’t think the !raffle app is a Wimp program. Does it matter and how do you tell? |
David J. Ruck (33) 1635 posts |
If it isn’t a Wimp program the application which starts it will be suspended until the program exits. Only if the new program calls Wimp_Initialise will its task handle be returned. |
Herbert Doerfler (8783) 5 posts |
You can use signals to make !AppB quit when !AppA does. Just catch the termination signal in !AppB and handle it gracefully. Check out the signal module in Python, it’s pretty handy for this kinda stuff. |