Python锁问题
我试图使用锁来处理对多线程应用程序中共享资源的线程访问,但事情并没有按预期进行。请参阅以下代码块(python) 这是输出Python锁问题,python,multithreading,tkinter,locking,Python,Multithreading,Tkinter,Locking,我试图使用锁来处理对多线程应用程序中共享资源的线程访问,但事情并没有按预期进行。请参阅以下代码块(python) 这是输出 attempting to acquire display mutex for update display mutex acquired for update trying shutdown waking up 不,这并不是我所说的,但它说明了这个想法。我已经在update方法中插入了一个延迟,因此我预期会发生以下情况: 调用更新方法 更新方法获取互斥并等待计时器 sh
attempting to acquire display mutex for update
display mutex acquired for update
trying shutdown
waking up
不,这并不是我所说的,但它说明了这个想法。我已经在update方法中插入了一个延迟,因此我预期会发生以下情况:
...
attempting to acquire display mutex for update
display mutex acquired for update
trying shutdown
waking up
attempting to release mutex for update
display mutex released
#'done...' might appear on any line now
mutex acquired...
shutdown done
很明显,这不是正在发生的事情,我也不知道为什么。问题似乎集中在设置tkinter GUI对象的样式(或与之交互)上。在调用设置样式之前,事情不会停止(您可以看到“唤醒”消息已发送)
除了在uuu init_uuuu()中调用构造函数外,代码中只有两个引用了锁/互斥锁
实际上,我在“关机”中所做的唯一一件事就是在此时获取并释放互斥体;如果我不这样做,一切都会正常进行:更新会继续进行并正常退出。只有在“关机”中获得互斥时,事情才会失败。知道发生了什么事吗?那我的假设是错误的呢?一般来说,您只能在创建tkinter对象的线程中调用这些对象的方法。
...
attempting to acquire display mutex for update
display mutex acquired for update
trying shutdown
waking up
attempting to release mutex for update
display mutex released
#'done...' might appear on any line now
mutex acquired...
shutdown done