kylebarron / stata_kernel

A Jupyter kernel for Stata. Works with Windows, macOS, and Linux.
https://kylebarron.dev/stata_kernel/
GNU General Public License v3.0
266 stars 57 forks source link

How to make jupyter automatically close the stata session #425

Open Gritbadger opened 2 years ago

Gritbadger commented 2 years ago

Hi,thank you for writing stata_kernel, which is very convenient to use. I can use python's powerful data functions and stata's powerful statistical functions at the same time.

But there is a problem, that is, whenever I use jupyterlab to create a new stata notebook, execute the stata command, and finally close the stata notebook, but jupyter will not automatically close the stata process, I have to enter the Windows task window every time, and manually close the stata process, which makes me Very convenient. Is there a way to fix this?

kylebarron commented 2 years ago

Looks like this is supposed to be handled through do_shutdown. We do call self.stata.shutdown() https://github.com/kylebarron/stata_kernel/blob/b7cd97223827fa095c27774d7b6b81434ac4b97c/stata_kernel/kernel.py#L340 which tries to run exit, clear in Stata: https://github.com/kylebarron/stata_kernel/blob/b7cd97223827fa095c27774d7b6b81434ac4b97c/stata_kernel/stata_session.py#L577-L578

Not sure off the top of my head why that wouldn't work in Windows. Maybe config.get('execution_mode') isn't set properly on Windows. We could switch that to if is_windows() or config.get('execution_mode') == 'automation':