stata_kernel
stata_kernel copied to clipboard
Fix exit behavior
When I type exit, it seems pexpect is waiting for some response when there will never be one
https://stackoverflow.com/questions/320232/ensuring-subprocesses-are-dead-on-exiting-python-program
You have to catch pexpect.exceptions.EOF
I don't know how to stop the kernel from inside Python?
As a temporary fix, when you catch EOF, you can do
except pexpect.exceptions.EOF:
self.stata_exit = True
Then in do_execute hack your way around it:
if self.stata.stata_exit:
ident = self._topic('shutdown')
parent = {'content': {'restart': True}, 'header': {}, 'ident': ident}
self.shutdown_request(self.iopub_socket, ident, parent)
super(StataKernel, self).__init__()
return return_obj
Not very good, but it would prevent a crash (so as a temporary patch if might be OK). Since this restarts Stata instead of exiting, maybe a message alerting the user they have to exit through the GUI.
Ah I just didn't know about the self.shutdown_request method.
Eh...it's a hack, because I tried it with restart set to False and it didn't work.
Also see: https://github.com/jupyter/jupyter_client/issues/237
Thanks for the link
Is there a proper way to shut down the kernel? It seems that Stata.exe will still be running after I close my jupyter lab or nteract, which prevent windows from restarting or making any changes (e.g. renaming the file) so that I have to manually end it in task manager. And sometimes I even see multiple Stata.exe were still running in task manager after I closed everything.
I actually have to test this.. I think on Windows I might not have coded the shutdown of the Stata window
When you stop the Jupyter server, it should close all the Stata windows.
There were no Stata windows since the update you made last time, but Stata.exe will be stilling running.
On my Windows test machine, when I stop the Jupyter server, it stops the Stata.exe process it's connected to.
I usually just close my chrome tab first and then close my cmd window. Is this the right way to shut down everything?
If you do Ctrl+C twice in the command window, that should stop the Jupyter server.
@kylebarron weird thing is that it only happened sometimes. It just happened again after I pressed Ctrl + C twice.

I rarely work on Windows, so it's time consuming for me to debug. I'm not really sure what the issue is.
It's a known issue, however, that if you already have Stata windows open, it may connect to an already open one.
@kylebarron Thank you. that's fine for me. No worries...