Python 2.7. I have a GUI written with Tkinter that creates a separate thread to run a task so that the GUI is not blocked while it runs. There is no locking implemented anywhere:
class MainWindow(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.initialize()
def initialize(self):
# Configure the window, buttons etc
def button_function(self):
t = threading.Thread(target=self.myfunction)
t.daemon = True
t.start()
return
def myfunction(self);
# Calls a function in an imported module
When I run this the GUI hangs, and then crashes without traceback. It does not crash if I call the function in the main thread (although the GUI does 'freeze' while myfunction is running):
def button_function(self):
self.myfunction() # Runs fine
return
The function itself can sometimes store several MB in memory while running. Commenting out the larger variables allows the function to return successfully.
I should add that the child thread makes no calls to GUI functions. The GUI is just a wrapper around a separate command line function.
I suspect the correct solution would be to either write out larger variables into temporary files, or re-architect the function to return to the main thread more often.
Is there a restriction on memory usage in child threads, and if so, how is this configured?
There's no memory limit in child threads.
(I encourage favoretti or mcy to post a similar answer for acceptance, so this doesn't join the infinite queue of unanswered questions. There's nothing wrong with OP answering his own question.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With