+ 8
Why the window is closing unexpectedly ?
I made a GUI using Tkinter. I'm debugging with VS Code. There are 5 threads So I fixed many excetions but Now it's closing no exception. Sometimes it works 15 minutes Sometimes it works 3 minutes. Idk why 😧
14 ответов
+ 6
Pedro H.J This is an advanced topic that will require you to spend some time learning all about multi-threaded programming concepts, best practices, challenges, mitigation strategies, etc. I won't do the effort justice in a SoloLearn answer.
This issue, in particular, is a classic thread lock contention resulting from concurrent background threads attempting to operate on a shared resource. However, it's further complicated as the shared resource is tied to the main GUI thread. Without any safeguards in place for any sort of locking or synchronizing controls on these thread operations, the behavior will be unpredictable.
One possible scenario explaining this issue is a race condition is occurring when thread A attempts to update the label that is also being updated by thread B. The main GUI thread throws an exception without releasing a lock to be handed to another thread allowing the next thread to do work. This could then result in the GUI freezing or crashing.
+ 9
Thank you Gordon
Thank you David Carroll
Thank you a ton
+ 8
I made 4 threads using Lock 👇👇👇 it works
https://www.sololearn.com/post/160671/?ref=app
+ 7
I've collected a few links that dig into a few important concepts to help with understanding challenges related to multi-threaded programming.
http://stupidpythonideas.blogspot.com/2013/10/why-your-gui-app-freezes.html?m=1
https://web.mit.edu/6.005/www/fa15/classes/23-locks/#synchronization
https://en.m.wikipedia.org/wiki/Lock_(computer_science)
https://en.m.wikipedia.org/wiki/Race_condition
I hope these are helpful.
+ 6
I found the problem. Many thread to set text label .
I need to read bluetooth, plot canvas points , read webcam then many thread.
What is the best way ? Semaphore ? Observer ?
+ 6
# I'm testing thread and simple GUI
# I tried 4 thread then it does not work very well
def t1(self):
while True:
self.Label1.configure(text="teste 1")
#time.sleep(2)
def t2(self):
while True:
self.Label1.configure(text="teste 2")
#time.sleep(1)
def t3(self):
while True:
self.Label1.configure(text="teste 1")
#time.sleep(2)
def t4(self):
while True:
self.Label1.configure(text="teste 2")
# Threads
self.a = threading.Thread(target=self.t1)
self.a.start()
self.b = threading.Thread(target=self.t2)
self.b.start()
self.c = threading.Thread(target=self.t3)
self.c.start()
self.d = threading.Thread(target=self.t4)
self.d.start()
+ 6
Mirielle🐶 My main code there are 1800 lines many Tkinter lines then I made a simple GUI to test thread and one Label. 👆👆 See above
+ 5
I tried Google and stackoverflow but not sucess 😦
+ 2
thread?
maybe... David?
+ 1
+ 1
I think that u should use yrr thread and try againn
0
Do you knows how to use thread.join()? Google search for it