Replies: 1 comment 4 replies
-
Hi, import os
import sys
import traceback
from pathlib import Path
import psutil
import win32api
import win32con
import win32console
BASE_DIR = Path(__file__).parent
def on_exit(signal):
with open(BASE_DIR / "signal_acad.txt", "w") as f:
evt = {
win32con.CTRL_C_EVENT: "CTRL_C_EVENT",
win32con.CTRL_BREAK_EVENT: "CTRL_BREAK_EVENT",
win32con.CTRL_CLOSE_EVENT: "CTRL_CLOSE_EVENT",
win32con.CTRL_LOGOFF_EVENT: "CTRL_LOGOFF_EVENT",
win32con.CTRL_SHUTDOWN_EVENT: "CTRL_SHUTDOWN_EVENT",
}.get(signal, None)
print(evt, file=f)
if evt:
print(evt)
return 0 if evt == "CTRL_C_EVENT" else 1
def main():
win32console.FreeConsole()
win32console.AllocConsole()
win32api.SetConsoleCtrlHandler(on_exit, True)
f_stdout = open("CONOUT$", "w")
sys.stdout = sys.stderr = f_stdout
print("Attached ...")
def PyRxCmd_doit():
try:
main()
proccess = psutil.Process(os.getpid())
print(proccess.name())
print("DONE")
except Exception:
traceback.print_exc() |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I run such code in python:
everything works as expected
but when I run similar code in CAD environment by connecting to the console of existing python process it seems that
SetConsoleCtrlHandler
does not register the handler - ZWCAD is closed immediately:Beta Was this translation helpful? Give feedback.
All reactions