A script with both tkFileDialog and pyperclip imported won't exit. (Python2.7) Working examples, where my script exits as expected:
import Tkinter, tkFileDialog
root = Tkinter.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
root.destroy()
As well as:
import pyperclip
print ('whatever')
Yet the following will prevent my script from exiting (raise SystemExit
added for emphasis):
import Tkinter, tkFileDialog
import pyperclip
root = Tkinter.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
root.destroy()
raise SystemExit
Just importing both modules works fine, a tkFileDialog must be opened in order to create the error.
Calling os._exit()
or any code that raises SystemExit
soft-locks the interpreter or the python-process, when called as a script.
It seems, that the problem occurs when pyperclip
is loaded when opening a tkFileDialog
, since the following fragment works as expected:
import Tkinter, tkFileDialog
root = Tkinter.Tk()
root.withdraw()
file_path = tkFileDialog.askopenfilename()
root.destroy()
import pyperclip
raise SystemExit
In any case, though, every line of code after the critical part is executed as expected, raising SystemExit
will create a soft-lock though.
This can't be used as a workaround though since python doesn't allow unloading of modules.
What am I doing wrong? Any ideas for a workaround?