Merge "Implement the correct total ordering for scheduler.Timeout"

This commit is contained in:
Jenkins 2016-07-19 07:32:23 +00:00 committed by Gerrit Code Review
commit 2303d2e2c1
1 changed files with 5 additions and 16 deletions

View File

@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import functools
import sys import sys
import types import types
@ -48,6 +49,7 @@ def task_description(task):
return encodeutils.safe_decode(repr(task)) return encodeutils.safe_decode(repr(task))
@functools.total_ordering
class Timeout(BaseException): class Timeout(BaseException):
"""Raised when task has exceeded its allotted (wallclock) running time. """Raised when task has exceeded its allotted (wallclock) running time.
@ -79,28 +81,15 @@ class Timeout(BaseException):
return False return False
def __eq__(self, other): def __eq__(self, other):
return not self < other and not other < self if not isinstance(other, Timeout):
return NotImplemented
def __ne__(self, other): return not (self < other or other < self)
return not self.__eq__(other)
def __gt__(self, other):
return other < self
def __ge__(self, other):
return not self < other
def __le__(self, other):
return not other < self
def __lt__(self, other): def __lt__(self, other):
if not isinstance(other, Timeout): if not isinstance(other, Timeout):
return NotImplemented return NotImplemented
return self._duration.endtime() < other._duration.endtime() return self._duration.endtime() < other._duration.endtime()
def __cmp__(self, other):
return self < other
class TimedCancel(Timeout): class TimedCancel(Timeout):
def trigger(self, generator): def trigger(self, generator):