Better and now it's possible to do threading
import errno
import os
import pika
import errno
import os
import pika
import uuid
class TimeoutError(Exception):
import uuid
class TimeoutError(Exception):
if len(queues) == 0:
return None
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))
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)