summaryrefslogtreecommitdiff
path: root/python/examples/api/drain
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2010-02-13 13:24:52 +0000
committerRafael H. Schloming <rhs@apache.org>2010-02-13 13:24:52 +0000
commita025819835829ea7658e4886ddb6e5e488f916eb (patch)
tree99e4396825a7862c1d97917bcaeb95cdb07af28d /python/examples/api/drain
parentcd50c6ac6cb31df04c6b68731155cd75c37abced (diff)
downloadqpid-python-a025819835829ea7658e4886ddb6e5e488f916eb.tar.gz
handle Control-C
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@909811 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/examples/api/drain')
-rwxr-xr-xpython/examples/api/drain44
1 files changed, 24 insertions, 20 deletions
diff --git a/python/examples/api/drain b/python/examples/api/drain
index a852d29de7..f2d7a50058 100755
--- a/python/examples/api/drain
+++ b/python/examples/api/drain
@@ -73,26 +73,30 @@ class Formatter:
return eval(st, self.environ)
# XXX: should make URL default the port for us
-conn = Connection.open(url.host, url.port or AMQP_PORT,
- username=url.user,
- password=url.password,
- reconnect=opts.reconnect,
- reconnect_delay=opts.reconnect_delay,
- reconnect_limit=opts.reconnect_limit)
-ssn = conn.session()
-rcv = ssn.receiver(addr)
+conn = Connection(url.host, url.port or AMQP_PORT,
+ username=url.user,
+ password=url.password,
+ reconnect=opts.reconnect,
+ reconnect_delay=opts.reconnect_delay,
+ reconnect_limit=opts.reconnect_limit)
+try:
+ conn.connect()
+ ssn = conn.session()
+ rcv = ssn.receiver(addr)
-count = 0
-while not opts.count or count < opts.count:
- try:
- msg = rcv.fetch(timeout=timeout)
- print opts.format % Formatter(msg)
- count += 1
- ssn.acknowledge()
- except Empty:
- break
- except ReceiveError, e:
- print e
- break
+ count = 0
+ while not opts.count or count < opts.count:
+ try:
+ msg = rcv.fetch(timeout=timeout)
+ print opts.format % Formatter(msg)
+ count += 1
+ ssn.acknowledge()
+ except Empty:
+ break
+ except ReceiveError, e:
+ print e
+ break
+except KeyboardInterrupt:
+ pass
conn.close()