def list_running_servers(profile='default'): """Iterate over the server info files of running notebook servers. Given a profile name, find nbserver-* files in the security directory of that profile, and yield dicts of their information, each one pertaining to a currently running notebook server instance. """ pd = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), name=profile) for file in os.listdir(pd.security_dir): if file.startswith('nbserver-'): with io.open( os.path.join(pd.security_dir, file), encoding='utf-8') as f: info = json.load(f) # Simple check whether that process is really still running # Also remove leftover files from IPython 2.x without a pid field if ('pid' in info) and check_pid(info['pid']): yield info else: # If the process has died, try to delete its info file try: os.unlink(file) except OSError: pass # TODO: This should warn or log or something
def check_pid(self, pid): try: return check_pid(pid) except Exception: self.log.warn("Could not determine whether pid %i is running. " " Making the likely assumption that it is." % pid) return True
def check_pid(self, pid): try: return check_pid(pid) except Exception: self.log.warn( "Could not determine whether pid %i is running. " " Making the likely assumption that it is."%pid ) return True
def check_alive(self): if not check_pid(self.pid): return False try: requests.head(self.url) return True except requests.ConnectionError: return False
def wait_for_pid_file(filename, timeout=20): for i in range(timeout): #pylint: disable=W0612 try: with open(filename, 'r') as f: pid = int(f.readline()) if check_pid(pid): return True except Exception: pass time.sleep(1) return False
def list_running_servers(profile='default'): """Iterate over the server info files of running notebook servers. Given a profile name, find nbserver-* files in the security directory of that profile, and yield dicts of their information, each one pertaining to a currently running notebook server instance. """ pd = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), name=profile) for file in os.listdir(pd.security_dir): if file.startswith('nbserver-'): with io.open(os.path.join(pd.security_dir, file), encoding='utf-8') as f: info = json.load(f) # Simple check whether that process is really still running if check_pid(info['pid']): yield info else: # If the process has died, try to delete its info file try: os.unlink(file) except OSError: pass # TODO: This should warn or log or something
def wait(self, interval=0.01): # os.waitpid() only works with child processes, so we need a busy loop pid = self.pid while check_pid(pid): time.sleep(0.01)