So, I’m building a GUI in Python using Tkinter which will be used to, during runtime, load a textfile listing a number of python scripts. The scripts will then be executed and return a number indicating whether they were successful or not (returncode will not be returned with sys.exit, script files will have a function which will be called and return a 1 or a 0). During runtime I use exec to import the script files as modules and then call the function within the module with eval.
def runtest(test):
exec 'import ' + test
func=test+'.'+test+'()'
return eval(func)
Problem is, the whole UI hangs during the evaluation, but I would rather have it running in the background. Would be much appreciated if anyone know of a way to make this happen.
There could be 2 ways.
Use Python multiprocessing library http://docs.python.org/library/multiprocessing.html
Python thread.
Option 1 is good compared to Option 2 due to Python’s GIL.
from multiprocessing import Process