Issue
On Windows 11, with zprocess 2.27.1, when running BLACS from a ConPTY console (VS Code integrated terminal or Windows Terminal), recompiling the connection table and then pressing Restart blacs crashes BLACS during startup with SetConsoleMode error 87 in zprocess.
Traceback
Traceback (most recent call last):
File "C:\Users\dbloch\labscript-suite\blacs\blacs\__main__.py", line 15, in <module>
import labscript_utils.excepthook
File "C:\Users\dbloch\labscript-suite\labscript-utils\labscript_utils\__init__.py", line 101, in <module>
zprocess.disable_quick_edit()
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "C:\Users\dbloch\labscript-suite\userlib\.venv\Lib\site-packages\zprocess\utils.py", line 190, in disable_quick_edit
console.SetConsoleMode(new_mode)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
pywintypes.error: (87, 'SetConsoleMode', 'The parameter is incorrect.')
Possible cause
In disable_quick_edit(), the Get call is wrapped in try/except pywintypes.error, but the Set call is not, so the exception propagates:
# zprocess/utils.py
if (orig_mode & ENABLE_EXTENDED_FLAGS) and not (orig_mode & ENABLE_QUICK_EDIT):
return
new_mode = (orig_mode | ENABLE_EXTENDED_FLAGS) & ~ENABLE_QUICK_EDIT
console.SetConsoleMode(new_mode) # <-- unguarded, raises error 87 in a ConPTY
This only surfaces on restart, not first launch: SetConsoleMode() always fails in a ConPTY, so the crash happens only when the early-return guard above is not taken.
On first launch the console mode satisfies the guard and the call is skipped.
The relaunched process inherits a console mode that no longer satisfies it, so SetConsoleMode() runs and fails.
Quick fix
By putting the same try/except for SetConsoleMode() than GetConsoleMode() this avoids the crash:
try:
console.SetConsoleMode(new_mode)
except pywintypes.error:
return
atexit.register(console.SetConsoleMode, orig_mode)
Issue
On Windows 11, with zprocess 2.27.1, when running BLACS from a ConPTY console (VS Code integrated terminal or Windows Terminal), recompiling the connection table and then pressing Restart blacs crashes BLACS during startup with
SetConsoleModeerror 87 in zprocess.Traceback
Possible cause
In
disable_quick_edit(), theGetcall is wrapped intry/except pywintypes.error, but theSetcall is not, so the exception propagates:This only surfaces on restart, not first launch:
SetConsoleMode()always fails in a ConPTY, so the crash happens only when the early-return guard above is not taken.On first launch the console mode satisfies the guard and the call is skipped.
The relaunched process inherits a console mode that no longer satisfies it, so
SetConsoleMode()runs and fails.Quick fix
By putting the same try/except for
SetConsoleMode()thanGetConsoleMode()this avoids the crash: