If you don't remember to call UnregisterForSystemEvent after registering a shutdown handler, when the kernel is shutdown you get a segfault. Here's a sample in Python, but I also did it in Tcl. Originally I was looking into why we had to have a special atexit handler in the Python SML test script in the past, and I whittled down to this MBE; I don't really see how an atexit handler that shuts down the kernel would help here, though, so it might be a separate issue.
try:
from Python_sml_ClientInterface import *
except ImportError:
from soar_sml import *
# also fails
# kernel = Kernel.CreateKernelInNewThread()
kernel = Kernel.CreateKernelInCurrentThread()
shutdownCallbackId = kernel.RegisterForSystemEvent(smlEVENT_BEFORE_SHUTDOWN, lambda: 1+1, None)
# Fixes the segfault!
# kernel.UnregisterForSystemEvent(shutdownCallbackId)
print("shutting down kernel")
# segfaults
kernel.Shutdown()
# never prints
print("deleting kernel")
del kernel
print("finished")
If you don't remember to call
UnregisterForSystemEvent
after registering a shutdown handler, when the kernel is shutdown you get a segfault. Here's a sample in Python, but I also did it in Tcl. Originally I was looking into why we had to have a specialatexit
handler in the Python SML test script in the past, and I whittled down to this MBE; I don't really see how anatexit
handler that shuts down the kernel would help here, though, so it might be a separate issue.