python - TkInter deadlock -
Is there anything wrong with the following code? Running the same code, I get a standoff, where the main thread tries to get lock lock, where the loop does not belong to the pond.
In addition, since I can not post it without adding "more details", what would be a good statement in this case? The tanker thread is not secure. Use a queue for Tkinter manipulations or use the thread secure version mtTkinter () instead. (I went with MTNK.) did not want to be seen enough on the previously asked questions. The problem was addressed first, e.g. At: Import import of gold from imported gold from the import of import from Random Import Random Class Test (Tkinter.Tk): def __init __ (self, parent): Tkinter.Tk __int __ (self, parent) self. Promotions (false, false) themselves Grad () self _button = Tkinter.Button (auto, text = 'click me', command = self._foo) self._button.grid (column = 0, line = 0) self._lock = threading.Lock () def __enter __ (self ): Self._loopRunning = True self._loopThread = threading.Thread (target = self._loop) self._loopThread.start () back self def __ext___ (self, x_type, x_wall, traceback): self. _loopRunning = false self. _loopThread.join () Return the wrong def _loop (self): while self._loopRunning: The print 'loop lock wants' with itself. _lock: print 'loop acquired lock' self._button.configure () sleep (r endom ()) print 'loop lock should be released' print 'loop release lock' sleep (1) def _foo (self): print 'afoo Wants to lock 'to self._lock: print' foo acquired lock 'self._button.configure () sleep (random ()) print' release to foo lock 'print' foo released lock 'sleep (1) if __name__ ==' __main__ ': with test (none) as test: test.mainloop ()
Comments
Post a Comment