stata_kernel icon indicating copy to clipboard operation
stata_kernel copied to clipboard

Fix exit behavior

Open kylebarron opened this issue 7 years ago • 18 comments
trafficstars

When I type exit, it seems pexpect is waiting for some response when there will never be one

kylebarron avatar Aug 06 '18 02:08 kylebarron

https://stackoverflow.com/questions/320232/ensuring-subprocesses-are-dead-on-exiting-python-program

kylebarron avatar Aug 06 '18 15:08 kylebarron

You have to catch pexpect.exceptions.EOF

kylebarron avatar Aug 06 '18 22:08 kylebarron

I don't know how to stop the kernel from inside Python?

kylebarron avatar Aug 11 '18 23:08 kylebarron

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.

mcaceresb avatar Aug 14 '18 17:08 mcaceresb

Ah I just didn't know about the self.shutdown_request method.

kylebarron avatar Aug 14 '18 17:08 kylebarron

Eh...it's a hack, because I tried it with restart set to False and it didn't work.

mcaceresb avatar Aug 14 '18 18:08 mcaceresb

Also see: https://github.com/jupyter/jupyter_client/issues/237

mcaceresb avatar Aug 14 '18 18:08 mcaceresb

Thanks for the link

kylebarron avatar Aug 14 '18 18:08 kylebarron

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.

stevenlis avatar Sep 30 '18 14:09 stevenlis

I actually have to test this.. I think on Windows I might not have coded the shutdown of the Stata window

kylebarron avatar Sep 30 '18 17:09 kylebarron

When you stop the Jupyter server, it should close all the Stata windows.

kylebarron avatar Sep 30 '18 17:09 kylebarron

There were no Stata windows since the update you made last time, but Stata.exe will be stilling running.

stevenlis avatar Sep 30 '18 21:09 stevenlis

On my Windows test machine, when I stop the Jupyter server, it stops the Stata.exe process it's connected to.

kylebarron avatar Sep 30 '18 22:09 kylebarron

I usually just close my chrome tab first and then close my cmd window. Is this the right way to shut down everything?

stevenlis avatar Sep 30 '18 22:09 stevenlis

If you do Ctrl+C twice in the command window, that should stop the Jupyter server.

kylebarron avatar Oct 01 '18 14:10 kylebarron

@kylebarron weird thing is that it only happened sometimes. It just happened again after I pressed Ctrl + C twice. snipaste_551 snipaste_484

stevenlis avatar Oct 03 '18 00:10 stevenlis

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 avatar Oct 03 '18 15:10 kylebarron

@kylebarron Thank you. that's fine for me. No worries...

stevenlis avatar Oct 03 '18 15:10 stevenlis