+ 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 😧

14th Oct 2019, 11:16 AM
Pedro H.J
Pedro H.J - avatar
13 odpowiedzi
+ 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.
15th Oct 2019, 5:05 PM
David Carroll
David Carroll - avatar
+ 9
Thank you Gordon Thank you David Carroll Thank you a ton
15th Oct 2019, 6:49 PM
Pedro H.J
Pedro H.J - avatar
+ 8
I made 4 threads using Lock 👇👇👇 it works https://www.sololearn.com/post/160671/?ref=app
15th Oct 2019, 4:24 PM
Pedro H.J
Pedro H.J - avatar
+ 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.
15th Oct 2019, 5:08 PM
David Carroll
David Carroll - avatar
+ 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 ?
15th Oct 2019, 1:48 AM
Pedro H.J
Pedro H.J - avatar
+ 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()
15th Oct 2019, 1:50 AM
Pedro H.J
Pedro H.J - avatar
+ 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
15th Oct 2019, 1:53 AM
Pedro H.J
Pedro H.J - avatar
+ 5
I tried Google and stackoverflow but not sucess 😦
14th Oct 2019, 11:17 AM
Pedro H.J
Pedro H.J - avatar
+ 2
thread? maybe... David?
15th Oct 2019, 3:48 PM
Gordon
Gordon - avatar
14th Oct 2019, 11:53 AM
Gordon
Gordon - avatar
+ 1
I think that u should use yrr thread and try againn
14th Oct 2019, 1:24 PM
Sam Mishra
Sam Mishra - avatar
0
Do you knows how to use thread.join()? Google search for it
19th Oct 2019, 3:25 AM
周書祥
周書祥 - avatar
14th Oct 2019, 1:25 PM
Sam Mishra
Sam Mishra - avatar