|
74 | 74 | from IPython.nbformat.sign import NotebookNotary |
75 | 75 | from IPython.utils.importstring import import_item |
76 | 76 | from IPython.utils import submodule |
| 77 | +from IPython.utils.process import check_pid |
77 | 78 | from IPython.utils.traitlets import ( |
78 | 79 | Dict, Unicode, Integer, List, Bool, Bytes, Instance, |
79 | 80 | DottedObjectName, TraitError, |
@@ -844,6 +845,7 @@ def server_info(self): |
844 | 845 | 'secure': bool(self.certfile), |
845 | 846 | 'base_url': self.base_url, |
846 | 847 | 'notebook_dir': os.path.abspath(self.notebook_dir), |
| 848 | + 'pid': os.getpid() |
847 | 849 | } |
848 | 850 |
|
849 | 851 | def write_server_info_file(self): |
@@ -917,8 +919,17 @@ def list_running_servers(profile='default'): |
917 | 919 | for file in os.listdir(pd.security_dir): |
918 | 920 | if file.startswith('nbserver-'): |
919 | 921 | with io.open(os.path.join(pd.security_dir, file), encoding='utf-8') as f: |
920 | | - yield json.load(f) |
| 922 | + info = json.load(f) |
921 | 923 |
|
| 924 | + # Simple check whether that process is really still running |
| 925 | + if check_pid(info['pid']): |
| 926 | + yield info |
| 927 | + else: |
| 928 | + # If the process has died, try to delete its info file |
| 929 | + try: |
| 930 | + os.unlink(file) |
| 931 | + except OSError: |
| 932 | + pass # TODO: This should warn or log or something |
922 | 933 | #----------------------------------------------------------------------------- |
923 | 934 | # Main entry point |
924 | 935 | #----------------------------------------------------------------------------- |
|
0 commit comments