TiesdeKok / ipystata

Enables the use of Stata together with Python via Jupyter (IPython) notebooks.
192 stars 68 forks source link

Terminated 1 unattached Stata session(s). #10

Closed mbaker21231 closed 8 years ago

mbaker21231 commented 8 years ago

Hie Ties --

Sorry to drop by again, but I just had a quick question. I have ipystata up and running on both my office PC and my Home PC with great success! While my home PC (windows 10, Stata12) doesn't have this problem, my office PC does (windows 7, Stata12).

Sometimes, when I open up a notebook and import ipystata, when I am already running a session in another notebook I get the message:

Terminated 1 unattached Stata session(s).

This seems to happen whether or not the previously opened notebook is using a labelled session or not. Any ideas as to how/why this happens?

Best,

Matt

TiesdeKok commented 8 years ago

Hi Matt,

Not a problem, I am happy to help. The problem is that Stata Automation cannot reliability reconnect to a Stata Instance after it loses connection. This can result in Python creating many hidden Stata instances that are not attached to IPyStata, which might hog a lot of resources if the sessions are not properly closed (for example because the notebook kernel dies).

To circumvent this problem I included a clean-up routine that will look for Stata instances created previously by IPyStata that are not attached to the current notebook. This routine runs when the notebook server is closed but also when IPyStata is imported (in case the notebook server crashes and does not trigger the routine).

Admittedly this solution is not the most sophisticated because I did not consider the possibility of running multiple notebooks with IPyStata at the same time. I will put it on my longer term todo list to support multiple IPyStata notebooks at the same time, but there are some other technical difficulties that make it a bit tricky.

For now I would recommend to stick with running multiple sessions from one notebook instead. :smile:

mbaker21231 commented 8 years ago

Ties --

Makes perfect sense - I should also get in the habit of using some of the built-in tools you made for monitoring the number of sessions, etc.

Thanks!

Matt