Skip to content
This repository

The constructor of Client() checks for AssertionError in validate_url to open a file instead of connection to a URL if it fails. #872

wants to merge 1 commit into from

2 participants

Hannes Schulz Min RK
Hannes Schulz

The constructor of Client() checks for AssertionError in validate_url to open a file instead of connection to a URL if it fails.

When running python -O, this failed, since the assertions were optimized away and other (random) errors were thrown.
These random errors are not catched. IMHO one should not depend on the side effects of assertions, which has been done here.

Min RK

Fair point.

I overloaded the validate_url, which is really just supposed to check that a url is valid, but I used it in the client to distinguish between a url and a file, which is inappropriate, since assertions get optimized away.

Do you want to change the try/except in Client from:

except AssertionError:


if not util.is_url(url_or_file):

adding to parallel.util:

def is_url(url):
    """boolean check for whether a string is a zmq url"""
    if '://' not in url:
        return False
    proto, addr = url.split('://', 1)
    if proto.lower() not in ['tcp','pgm','epgm','ipc','inproc']:
        return False
    return True

That way the assertions in validate_url are never used for actual logic, and only used for actual validation, where assertions are appropriate, and appropriate to optimize away when you trust that you don't have certain errors.

Hannes Schulz

This definitely sounds cleaner than my (minimum-impact-solution-) patch, I'd go with your solution!

Min RK

Did you want to make those changes to your PR, or shall I just make the change?

Hannes Schulz

I changed my commit as you suggested.

Min RK

This needs to be util.is_url, otherwise it gets a NameError. Also, it's indented by a tab instead of 8 spaces for some reason.

Min RK

Since it's a tiny typo, I'll go ahead and fix it in the merge. Thanks!

Min RK minrk closed this pull request from a commit October 17, 2011
Min RK fix is_url typo in parallel client
closes #872
Min RK minrk closed this in 4332951 October 17, 2011
Brian E. Granger ellisonbg referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Oct 17, 2011
Hannes Schulz introduce is_url() replacing validate_url() in cases where it is used…
… in a control structure (as opposed to an assert)
This page is out of date. Refresh to see the latest.
4  IPython/parallel/client/
@@ -306,9 +306,7 @@ def __init__(self, url_or_file=None, profile=None, profile_dir=None, ipython_dir
306 306
         assert url_or_file is not None, "I can't find enough information to connect to a hub!"\
307 307
             " Please specify at least one of url_or_file or profile."
308 308
-        try:
-            util.validate_url(url_or_file)
-        except AssertionError:
+	if not is_url(url_or_file):
312 310
             if not os.path.exists(url_or_file):
313 311
                 if self._cd:
314 312
                     url_or_file = os.path.join(self._cd.security_dir, url_or_file)
9  IPython/parallel/
@@ -108,6 +108,15 @@ def asbytes(s):
108 108
         s = s.encode('ascii')
109 109
     return s
110 110
+def is_url(url):
+    """boolean check for whether a string is a zmq url"""
+    if '://' not in url:
+        return False
+    proto, addr = url.split('://', 1)
+    if proto.lower() not in ['tcp','pgm','epgm','ipc','inproc']:
+        return False
+    return True
111 120
 def validate_url(url):
112 121
     """validate a url for zeromq"""
113 122
     if not isinstance(url, basestring):

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.