Skip to content

Commit

Permalink
examples: Fix samples
Browse files Browse the repository at this point in the history
Fix #11

* Replace `protocol.close_client()` by `protocol.close()` and
`protocol.wait_closed()`.
* Remove sleeps
  • Loading branch information
Thomas Recouvreux committed May 19, 2014
1 parent ee09927 commit 66c3187
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 22 deletions.
5 changes: 2 additions & 3 deletions examples/emit_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ def exchange_routing():
message = ' '.join(sys.argv[1:]) or "info: Hello World!"

yield from channel.exchange(exchange_name, 'fanout')
yield from asyncio.sleep(2)

yield from channel.publish(message, exchange_name=exchange_name, routing_key='')
print(" [x] Sent %r" % (message,))

yield from asyncio.sleep(1)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)
protocol.close()
yield from protocol.wait_closed()


asyncio.get_event_loop().run_until_complete(exchange_routing())
5 changes: 2 additions & 3 deletions examples/emit_log_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ def exchange_routing():
message = ' '.join(sys.argv[2:]) or 'Hello World!'

yield from channel.exchange(exchange_name, 'direct')
yield from asyncio.sleep(2)

yield from channel.publish(
message, exchange_name=exchange_name, routing_key=severity)
print(" [x] Sent %r" % (message,))

yield from asyncio.sleep(1)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)
protocol.close()
yield from protocol.wait_closed()


asyncio.get_event_loop().run_until_complete(exchange_routing())
Expand Down
5 changes: 2 additions & 3 deletions examples/emit_log_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ def exchange_routing():
routing_key = sys.argv[1] if len(sys.argv) > 1 else 'anonymous.info'

yield from channel.exchange(exchange_name, 'topic')
yield from asyncio.sleep(2)

yield from channel.publish(
message, exchange_name=exchange_name, routing_key=routing_key)
print(" [x] Sent %r" % (message,))

yield from asyncio.sleep(1)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)
protocol.close()
yield from protocol.wait_closed()


asyncio.get_event_loop().run_until_complete(exchange_routing())
5 changes: 2 additions & 3 deletions examples/new_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ def exchange_routing():
}

yield from asyncio.wait_for(channel.queue(queue_name, durable=True), timeout=10)
yield from asyncio.sleep(2)

yield from channel.publish("Message ", '', queue_name, properties=message_properties)
print(" [x] Sent %r" % (message,))

yield from asyncio.sleep(1)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)
protocol.close()
yield from protocol.wait_closed()


asyncio.get_event_loop().run_until_complete(exchange_routing())
4 changes: 3 additions & 1 deletion examples/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def produce():
while True:
yield from channel.publish("py3.message", '', queue_name)
yield from asyncio.sleep(10)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)

protocol.close()
yield from protocol.wait_closed()

asyncio.get_event_loop().run_until_complete(produce())
3 changes: 0 additions & 3 deletions examples/receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ def receive():
queue_name = 'py2.queue'

yield from asyncio.wait_for(channel.queue(queue_name, durable=False, auto_delete=True), timeout=10)
yield from asyncio.sleep(2)

yield from asyncio.wait_for(channel.basic_consume(queue_name), timeout=10)

while True:
consumer_tag, delivery_tag, message = yield from channel.consume()
print("consumer {} recved {} ({})".format(consumer_tag, message, delivery_tag))
yield from asyncio.sleep(10)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)


asyncio.get_event_loop().run_until_complete(receive())
3 changes: 1 addition & 2 deletions examples/receive_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def receive_log():
while True:
consumer_tag, delivery_tag, message = yield from channel.consume()
print("consumer {} recved {} ({})".format(consumer_tag, message, delivery_tag))
yield from asyncio.sleep(10)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)


asyncio.get_event_loop().run_until_complete(receive_log())
3 changes: 1 addition & 2 deletions examples/receive_log_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def receive_log():
while True:
consumer_tag, delivery_tag, message = yield from channel.consume()
print("consumer {} recved {} ({})".format(consumer_tag, message, delivery_tag))
yield from asyncio.sleep(10)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)


asyncio.get_event_loop().run_until_complete(receive_log())
3 changes: 1 addition & 2 deletions examples/receive_log_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def receive_log():
while True:
consumer_tag, delivery_tag, message = yield from channel.consume()
print("consumer {} recved {} ({})".format(consumer_tag, message, delivery_tag))
yield from asyncio.sleep(10)
yield from asyncio.wait_for(protocol.client_close(), timeout=10)


asyncio.get_event_loop().run_until_complete(receive_log())

0 comments on commit 66c3187

Please sign in to comment.