I had similar issues, and it was caused by an embedded matplotlib plot.
Running the following when quitting resolved the issue.
plt.close("all")