I'm trying to implement an event driven process with system call or subprocess. Basically I want to launch a non-blocking system command and upon completion of that system call, I want a function to be called. This is so that I can start a GUI progress bar, launch a system command and have the progress bar continue, and when the system call finishes, have the progress bar stop.
What I want to absolutely NOT DO, is to spawn a process, get its process ID and keep checking for the completion of that process in a while loop.
Below is just an example of how I imagine this should work (All of these are inside a class)
def launchTool(self):
self.progressbar.config(mode = 'indeterminate')
self.progressbar.start(20)
self.launchButton.config(state = 'disabled')
self.configCombobox.config(state = 'disabled')
## here the "onCompletion" is a pointer to a function
call("/usr/bin/make psf2_dcf", shell=True, onCompletion = self.toolCompleted)
def onCompletion(self):
print('DONE running Tool')
self.progressbar.stop()
self.launchButton.config(state = 'normal')
self.configCombobox.config(state = 'normal')
To avoid polling subprocess' status, you could use
SIGCHLD
signal on Unix. To combine it with tkinter's event loop, you could use the self-pipe trick. It also workarounds the possible tkinter + signal issue without the need to wake the event loop periodically.Output