obspy.core.util.misc._py3_windowsconsoleio_workaround

_py3_windowsconsoleio_workaround()[source]

This monkey patch prevents crashing Py >=3.6 under Windows while using the SuppressOutput context manager.

Python 3.6 implemented unicode console handling for Windows. This works by reading/writing to the raw console handle using {Read,Write}ConsoleW. The problem is that we are going to dup2 over the stdio file descriptors when doing FDCapture and this will CloseHandle the handles used by Python to write to the console. Though there is still some weirdness and the console handle seems to only be closed randomly and not on the first call to CloseHandle, or maybe it gets reopened with the same handle value when we suspend capturing. The workaround in this case will reopen stdio with a different fd which also means a different handle by replicating the logic in “Py_lifecycle.c:initstdio/create_stdio”.

See https://github.com/pytest-dev/py/issues/103 See http://bugs.python.org/issue30555 See https://github.com/obspy/obspy/issues/3148#issuecomment-1274254892