← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~adeuring/lp-dev-utils/select.error-withour-errno-attr into lp:lp-dev-utils

 

Abel Deuring has proposed merging lp:~adeuring/lp-dev-utils/select.error-withour-errno-attr into lp:lp-dev-utils.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~adeuring/lp-dev-utils/select.error-withour-errno-attr/+merge/126420

This morning I got an AttributeError while trying to start an EC2 test. The error occured in line 669 of ec2test/instance.py:

    665         while 1:
    666             try:
    667                 select.select([session], [], [], 0.5)
    668             except (IOError, select.error), e:
    669                 if e.errno == errno.EINTR:
    670                     continue

Poking around in the C source of the select module showed that select.error exceptions are always raised by calling PyErr_SetFromErrno(SelectError). (Well, OK, for Windows, another function is used, but I think we can ignore that here.) From the documentation of this function (http://docs.python.org/c-api/exceptions.html#PyErr_SetFromErrno):

 "This is a convenience function to raise an exception when a C library function has returned an error and set the C variable errno. It constructs a tuple object whose first item is the integer errno value and whose second item is the corresponding error message..."

So, no attribute named "value". But e[0] is an integer with the value of the C errno variable.

I left the old attempt to access e.errno in the code because I don't know if some older version of Python may have generated a error object with the attribute errno.

-- 
https://code.launchpad.net/~adeuring/lp-dev-utils/select.error-withour-errno-attr/+merge/126420
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~adeuring/lp-dev-utils/select.error-withour-errno-attr into lp:lp-dev-utils.
=== modified file 'ec2test/instance.py'
--- ec2test/instance.py	2012-08-07 07:15:13 +0000
+++ ec2test/instance.py	2012-09-26 10:04:19 +0000
@@ -666,7 +666,11 @@
             try:
                 select.select([session], [], [], 0.5)
             except (IOError, select.error), e:
-                if e.errno == errno.EINTR:
+                try:
+                    error_number = e.errno
+                except AttributeError:
+                    error_number = e[0]
+                if error_number == errno.EINTR:
                     continue
             if session.recv_ready():
                 data = session.recv(4096)