X-Git-Url: https://git.jsancho.org/?p=pyrabbit.git;a=blobdiff_plain;f=pyrabbit.py;h=351e98d6d39994afe7ce3271ae8a952b901740f7;hp=5b47b4dd273b416a44ed344cb7339b6b796b7d72;hb=HEAD;hpb=659feb5dc696d8e37061ce88f12c52e77e75b8bc diff --git a/pyrabbit.py b/pyrabbit.py index 5b47b4d..351e98d 100644 --- a/pyrabbit.py +++ b/pyrabbit.py @@ -22,7 +22,7 @@ import errno import os import pika -import signal +import time import uuid class TimeoutError(Exception): @@ -54,26 +54,24 @@ class Connection(object): if len(queues) == 0: return None - def _handle_timeout(signum, frame): + t_start = time.time() + method = None + i = 0 + delay = 0.0 + while method is None and (time.time()-t_start < timeout or timeout <= 0): + time.sleep(delay) + if delay < 1: + delay += 0.01 + method, properties, body = self.channel.basic_get(queues[i]) + if i == len(queues) - 1: + i = 0 + else: + i += 1 + + if method is None: raise TimeoutError(os.strerror(errno.ETIME)) - signal.signal(signal.SIGALRM, _handle_timeout) - signal.alarm(timeout) - - res = None - try: - method = None - i = 0 - while method is None: - method, properties, body = self.channel.basic_get(queues[i]) - if i == len(queues) - 1: - i = 0 - else: - i += 1 - res = Message(self, method, properties, body) - finally: - signal.alarm(0) - - return res + else: + return Message(self, method, properties, body) class Queue(object):