Here is my problem: Using Tkinter, I want to click a button and launch a python script. This python script is now a module (I don't know if it s the best way to do it) imported to my main script. This script should be running in background. There is a method in it to quit it. How can I call it ? I wanted to pass a flag or something to the module but I don't know how to do that.
For now, I call my code like that: in gui.py
import sniffer_wideband_v09
from Tkinter import *
root = Tk()
def handle_click():
global t
global stop_flag
stop_flag = 0
def callback():
sniffer_wideband_v09.main(sampling_rates, center_frequencies, gains, file_dir, files_names)
t = Thread(target=callback)
t.start()
root.mainloop()
I would like to call the quitting() method in sniffer_wideband_v09.py. Or to pass a flag to my module to stop the infinite loop. Afterward, I will need to bind all of this to Tkinter Buttons.
I did a bit of research on the question and found :
Is there any way to kill a Thread in Python? along with How to run a function in the background of tkinter and How to run and stop an infinite loop in a python thread
The first is promising, but I don't fully understand it, I'm working on it.
Note: I run it directly from my shell with ./gui.py and I am under Ubuntu, not windows.(I think it can change some ways of dealing with multi threading).
Thanks for the reading, any hint or help will be appreciated. I will post my code if I find a response in the mean time.
Edit: To give more info about the script launched in the thread : (it is a GNURadio script)
class foo():
def __init__(self):
self.parameters()
def methods():
self.dostuff()
def main(sampling_rates, center_frequencies, gains, file_dir, files_names):
tb = foo()
while True: #flag could be here to exit the infinite while.
tb.start()
tb.stop()
def quitting():
tb.stop()
## not mandatory piece of code from now on
if __name = "__main__":
main()
quitting()