import asyncio
import asynqp
@asyncio.coroutine
def main_coro(loop):
# connect to the RabbitMQ broker
connection = yield from asynqp.connect(
'localhost', 5672, username='guest', password='guest')
# Open a communications channel
channel = yield from connection.open_channel()
disconnected_waiter = asyncio.Future()
try:
# Will never finish
yield from disconnected_waiter
except asyncio.CancelledError:
# Maybe we got KeyboardInterupt? Try to gracefully close everything
yield from channel.close()
yield from connection.close()
def main():
loop = asyncio.get_event_loop()
main_task = asyncio.async(main_coro(loop))
try:
loop.run_until_complete(main_task)
except KeyboardInterrupt:
main_task.cancel()
loop.run_until_complete(main_task)
if __name__ == "__main__":
main()
2) Close rabbitmq by ctl command rabbitmqctl stop (separate terminal)
3) Close script by ctrl+C
Expected result: Script closes
Real result: Script block on connection.close() call, as it can't receive ConnectionCloseOk frame.
How to reproduce: 1) Run this script
2) Close rabbitmq by ctl command
rabbitmqctl stop
(separate terminal) 3) Close script by ctrl+C Expected result: Script closes Real result: Script block onconnection.close()
call, as it can't receiveConnectionCloseOk
frame.