SIGHUP信号在python 2.7中给pika带来异常

时间:2014-10-09 15:33:33

标签: python-2.7 rabbitmq pika python-pika

我有一个鼠兔消费者 当我运行它并发送SIGHUP信号时,它给了我一个异常

Consumertest.py

import signal
import traceback
import pika
from time import sleep

received_signal = False

def signal_handler(signal, frame):
    global received_signal
    received_signal = True
    exit(1)

def sighup_handler(signal, frame):
    print "sighup received"


signal.signal(signal.SIGHUP, sighup_handler)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)

mq_server = "localhost"
mq_exchange = "my_exchange"
my_queue = "test_queue"

try:
    mq_connection = pika.BlockingConnection(pika.ConnectionParameters(mq_server))
except:

    exit(1)

mq_channel = mq_connection.channel()
mq_channel.exchange_declare(exchange=mq_exchange, durable=True)
mq_channel.queue_declare(queue=my_queue, durable=True)
mq_channel.queue_bind(my_queue, mq_exchange)
def callback(ch, method, properties, body):
    try:
        sleep(10)
        ch.basic_reject(delivery_tag=method.delivery_tag)

    except Exception as e:

        traceback.print_exc()  # region Message consumption

try:
    print ' [*] Waiting for messages. To exit press CTRL+C'
    mq_channel.basic_consume(callback, queue=my_queue)
    mq_channel.start_consuming()
except Exception as e:

    traceback.print_exc()

while True:
    pass

例外:

[*] Waiting for messages. To exit press CTRL+C
sighup received
Traceback (most recent call last):
  File "/run/media/bluto/04D0CF8ED0CF8500/Email_Projects/new_email_workers/testsigHup.py", line 47, in <module>
    mq_channel.start_consuming()
  File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 814, in start_consuming
    self.connection.process_data_events()
  File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 168, in process_data_events
    if self._handle_read():
  File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 271, in _handle_read
    if self._read_poller.ready():
  File "/usr/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 54, in ready
    events = self.poller.poll(self.poll_timeout)
error: (4, 'Interrupted system call')

0 个答案:

没有答案