X-Git-Url: https://git.jsancho.org/?p=pyrabbit.git;a=blobdiff_plain;f=pyrabbit.py;h=dfb9ac8f797051d6ad373962a89390c1ab85f48b;hp=5b47b4dd273b416a44ed344cb7339b6b796b7d72;hb=df284bf59c3d2eb7d900d39cc11df1c34558437f;hpb=659feb5dc696d8e37061ce88f12c52e77e75b8bc diff --git a/pyrabbit.py b/pyrabbit.py index 5b47b4d..dfb9ac8 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,21 @@ class Connection(object): if len(queues) == 0: return None - def _handle_timeout(signum, frame): + t_start = time.time() + method = None + i = 0 + while method is None and (time.time()-t_start < timeout or timeout <= 0): + time.sleep(0.1) + 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):