From ffce3749ab949e53c968d6e560c80e56ab3eb46d 2014-10-16 17:32:30 From: MinRK Date: 2014-10-16 17:32:30 Subject: [PATCH] even better IOError for no connection file --- diff --git a/IPython/parallel/client/client.py b/IPython/parallel/client/client.py index e237487..a50d214 100644 --- a/IPython/parallel/client/client.py +++ b/IPython/parallel/client/client.py @@ -47,6 +47,7 @@ from .view import DirectView, LoadBalancedView # Decorators for Client methods #-------------------------------------------------------------------------- + @decorator def spin_first(f, self, *args, **kwargs): """Call spin() to sync state prior to calling the method.""" @@ -58,6 +59,10 @@ def spin_first(f, self, *args, **kwargs): # Classes #-------------------------------------------------------------------------- +_no_connection_file_msg = """ +Failed to connect because no Controller could be found. +Please double-check your profile and ensure that a cluster is running. +""" class ExecuteReply(RichOutput): """wrapper for finished Execute results""" @@ -382,6 +387,11 @@ class Client(HasTraits): self._setup_profile_dir(self.profile, profile_dir, ipython_dir) + no_file_msg = '\n'.join([ + "You have attempted to connect to an IPython Cluster but no Controller could be found.", + "Please double-check your configuration and ensure that a cluster is running.", + ]) + if self._cd is not None: if url_file is None: if not cluster_id: @@ -389,13 +399,17 @@ class Client(HasTraits): else: client_json = 'ipcontroller-%s-client.json' % cluster_id url_file = pjoin(self._cd.security_dir, client_json) + if not os.path.exists(url_file): + msg = '\n'.join([ + "Connection file %r not found." % compress_user(url_file), + no_file_msg, + ]) + raise IOError(msg) if url_file is None: - raise ValueError( - "I can't find enough information to connect to a hub!" - " Please specify at least one of url_file or profile." - ) + raise IOError(no_file_msg) if not os.path.exists(url_file): + # Connection file explicitly specified, but not found raise IOError("Connection file %r not found. Is a controller running?" % \ compress_user(url_file) )