Why doesn't tkinter play nicely with multiprocessing?

前端 未结 2 1711
说谎
说谎 2020-12-19 09:36

The following code hangs without doing anything in python 3.2.2 in linux:

import tkinter
from multiprocessing import Process

def f():
    root = tkinter.Tk(         


        
2条回答
  •  忘掉有多难
    2020-12-19 09:59

    As of September 2013, there are some additional comments on the bug report that give more insight into what the actual problem is.

    http://bugs.python.org/issue5527#msg194848
    http://bugs.python.org/issue5527#msg195480

    Based on the above, I'm guessing something like the following is happening: Tkinter is not thread safe, so (for whatever reason) Tkinter wants to know which thread is the main thread. Tkinter assumes that the main thread when the Tkinter module is loaded will also be the main thread for program execution. When you fork or multiprocess after loading Tkinter, this assumption is broken. (For example, after a fork, the remembered main thread is in the parent, not the child.)

提交回复
热议问题