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()
label = tkinter.Label(root)
label.pack()
root.mainloop()
p = Process(target=f)
p.start()
The only information I have found about this problem is issue 5527, in which it is noted that the problem is with tkinter
being imported before the process is forked, that it can be fixed by importing tkinter
inside the function f
, and that the problem occurs in Linux but not Solaris.
Does anyone know what exactly is causing this problem, and if it is intentional or will eventually be fixed? Is there any workaround other than to import tkinter
locally everywhere I need it (which seems like bad style)? Do any other modules have similar issues with multiprocessing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…