I have multiple functions that when called, VSCode terminals and jupyter will get stuck and never execute. Here’s an example:
def get_file_path(filetype, filepath=''):
root = tk.Tk()
root.withdraw()
if not filepath:
filepath = tk.filedialog.askopenfilename(filetypes=[(filetype[0], ''.join(['*', filetype[1]]))])
path_dir = os.path.dirname(filepath)
common_string = os.path.basename(filepath)
common_string = common_string[0:-4]
return filepath, path_dir, common_string
if I call the function from the terminal get_file_path('.h5')
it will start the function and get stuck on the line where tkinter.filedialog.askopenfilename() is called.
I have a theory that VSCode thinks the window opened and is waiting for me to select a file on the window that never appeared, however matplotlib.pyplot.show()
will also freeze. It opens the window, but the plots don’t show and the windows “python is not responding” message will eventually come up, which doesn’t seem to match the theory.
I don’t get any errors, it just seems to be stuck/frozen. Jupyter will sometimes give a timeout, but the terminals just spin for eternity.
The issue only occurs in the VSCode Jupyter notebooks and integrated/debugging/interactive terminals. Everything works fine if I call these functions from an external terminal or run them in a script with the VScode debugger or interactive window.