diff options
author | Rafael H. Schloming <rhs@apache.org> | 2010-02-13 13:24:52 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2010-02-13 13:24:52 +0000 |
commit | a025819835829ea7658e4886ddb6e5e488f916eb (patch) | |
tree | 99e4396825a7862c1d97917bcaeb95cdb07af28d /python/examples/api/spout | |
parent | cd50c6ac6cb31df04c6b68731155cd75c37abced (diff) | |
download | qpid-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/spout')
-rwxr-xr-x | python/examples/api/spout | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/python/examples/api/spout b/python/examples/api/spout index ad98c486fd..97cb540c21 100755 --- a/python/examples/api/spout +++ b/python/examples/api/spout @@ -92,31 +92,35 @@ else: content = text # 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() -snd = ssn.sender(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() + snd = ssn.sender(addr) -count = 0 -start = time.time() -while (opts.count == 0 or count < opts.count) and \ - (opts.timeout is None or time.time() - start < opts.timeout): - msg = Message(content, reply_to=opts.reply_to) - msg.properties["spout-id"] = "%s:%s" % (spout_id, count) - for p in opts.properties: - name, val = nameval(p) - msg.properties[name] = val + count = 0 + start = time.time() + while (opts.count == 0 or count < opts.count) and \ + (opts.timeout is None or time.time() - start < opts.timeout): + msg = Message(content, reply_to=opts.reply_to) + msg.properties["spout-id"] = "%s:%s" % (spout_id, count) + for p in opts.properties: + name, val = nameval(p) + msg.properties[name] = val - try: - snd.send(msg) - count += 1 - print msg - except SendError, e: - print e - break + try: + snd.send(msg) + count += 1 + print msg + except SendError, e: + print e + break +except KeyboardInterrupt: + pass conn.close() |