Fix issue with running under pythonw.exe. See python issue 18298 for the background.