Skip to content

Commit fcfe97d

Browse files
FIX: Add platform-specific console termination handling in console_setup.py (#6766)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent c89c10f commit fcfe97d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

doc/changelog.d/6766.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add platform-specific console termination handling in console_setup.py

src/ansys/aedt/core/extensions/installer/console_setup.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def release(d):
113113
print("Error. AEDT should be started in gRPC mode in Linux to connect to PyAEDT")
114114
print("use ansysedt -grpcsrv portnumber command.")
115115
error = True
116-
if not error:
116+
if not error: # pragma: no cover
117117
print(" ")
118118

119119
print("\033[92m****************************************************************")
@@ -129,4 +129,30 @@ def release(d):
129129
print(" ")
130130
print(" ")
131131
print(" ")
132-
atexit.register(release, desktop)
132+
if is_windows:
133+
try:
134+
import win32api
135+
import win32con
136+
137+
def handler(ctrl_type):
138+
if ctrl_type == win32con.CTRL_CLOSE_EVENT:
139+
release(desktop)
140+
return False
141+
return True
142+
143+
win32api.SetConsoleCtrlHandler(handler, 1)
144+
except ImportError:
145+
atexit.register(release, desktop)
146+
else:
147+
try:
148+
import signal
149+
150+
def signal_handler(sig, frame):
151+
release(desktop)
152+
sys.exit(0)
153+
154+
signal.signal(signal.SIGHUP, signal_handler)
155+
signal.signal(signal.SIGTERM, signal_handler)
156+
except ImportError:
157+
pass
158+
atexit.register(release, desktop)

0 commit comments

Comments
 (0)