From 65f02a8d077031b3c19cc7c24dc9a28816ecd51b Mon Sep 17 00:00:00 2001 From: Jason R Briggs Date: Wed, 26 Aug 2015 14:08:45 +1200 Subject: [PATCH 1/3] catch generic exceptions on heartbeat send (issue #40 - https://github.com/jasonrbriggs/stomp.py/issues/40) --- stomp/listener.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stomp/listener.py b/stomp/listener.py index ae8b8182..f71d8c07 100755 --- a/stomp/listener.py +++ b/stomp/listener.py @@ -245,6 +245,9 @@ def __heartbeat_loop(self): self.transport.transmit(utils.Frame(None, {}, None)) except exception.NotConnectedException: log.debug("Lost connection, unable to send heartbeat") + except Exception: + _, e, _ = sys.exc_info() + log.debug("Unable to send heartbeat, due to: %s" % e) diff_receive = now - self.received_heartbeat From f5d502064e05526395ff6fcfd7bbd9531411788b Mon Sep 17 00:00:00 2001 From: Jason R Briggs Date: Wed, 26 Aug 2015 14:09:22 +1200 Subject: [PATCH 2/3] update changelog and version number --- CHANGELOG | 6 ++++++ stomp/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 7e5bc06e..0f78e211 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +Version 4.1.6 - Aug 2015 + + * Generic exception catch on heartbeat send + * + + Version 4.1.5 - Aug 2015 * Remove incorrect \r escaping from 1.1 protocol diff --git a/stomp/__init__.py b/stomp/__init__.py index af1bab9b..a98df11a 100755 --- a/stomp/__init__.py +++ b/stomp/__init__.py @@ -11,7 +11,7 @@ import stomp.connect as connect, stomp.listener as listener -__version__ = (4, 1, 5) +__version__ = (4, 1, 6) ## # Alias for STOMP 1.0 connections. From 6f4f7c5a67a90c94c1caf5dff26c762d82a90e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Sep 2015 15:59:45 +0300 Subject: [PATCH 3/3] Clean up some unused code --- stomp/__main__.py | 2 +- stomp/listener.py | 2 -- stomp/test/basic_test.py | 10 +++++----- stomp/test/p2_nonascii_test.py | 2 +- stomp/test/p3_nonascii_test.py | 8 ++++---- stomp/test/s10_test.py | 2 +- stomp/test/s12_test.py | 10 +++++----- stomp/test/ss_test.py | 2 +- stomp/test/testutils.py | 4 ++-- stomp/test/threading_test.py | 2 +- stomp/transport.py | 3 +-- stomp/utils.py | 2 +- 12 files changed, 23 insertions(+), 26 deletions(-) diff --git a/stomp/__main__.py b/stomp/__main__.py index 245ef4b3..fc9abfb3 100644 --- a/stomp/__main__.py +++ b/stomp/__main__.py @@ -480,7 +480,7 @@ def main(): help = 'Enable SSL connection') parser.set_defaults() - (options, args) = parser.parse_args() + (options, _) = parser.parse_args() if options.verbose == 'on': verbose = True diff --git a/stomp/listener.py b/stomp/listener.py index ae8b8182..ae242efe 100755 --- a/stomp/listener.py +++ b/stomp/listener.py @@ -231,7 +231,6 @@ def __heartbeat_loop(self): Main loop for sending (and monitoring received) heartbeats. """ send_time = time.time() - receive_time = time.time() while self.running: time.sleep(self.sleep_time) @@ -249,7 +248,6 @@ def __heartbeat_loop(self): diff_receive = now - self.received_heartbeat if diff_receive > self.receive_sleep: - receive_time = now diff_heartbeat = now - self.received_heartbeat if diff_heartbeat > self.receive_sleep: # heartbeat timeout diff --git a/stomp/test/basic_test.py b/stomp/test/basic_test.py index 08e41890..2a9c5ac8 100755 --- a/stomp/test/basic_test.py +++ b/stomp/test/basic_test.py @@ -125,7 +125,7 @@ def test_clientack(self): self.listener.wait_on_receipt() - (headers, msg) = self.listener.get_latest_message() + (headers, _) = self.listener.get_latest_message() message_id = headers['message-id'] subscription = headers['subscription'] @@ -140,7 +140,7 @@ def test_clientnack(self): self.listener.wait_on_receipt() - (headers, msg) = self.listener.get_latest_message() + (headers, _) = self.listener.get_latest_message() message_id = headers['message-id'] subscription = headers['subscription'] @@ -161,10 +161,10 @@ def test_specialchars(self): self.listener.wait_on_receipt() - (headers, msg) = self.listener.get_latest_message() + (headers, _) = self.listener.get_latest_message() - message_id = headers['message-id'] - subscription = headers['subscription'] + _ = headers['message-id'] + _ = headers['subscription'] self.assert_('special-1' in headers) self.assertEqual('test with colon : test', headers['special-1']) self.assert_('special-2' in headers) diff --git a/stomp/test/p2_nonascii_test.py b/stomp/test/p2_nonascii_test.py index 68bbda49..f5d9b4d0 100644 --- a/stomp/test/p2_nonascii_test.py +++ b/stomp/test/p2_nonascii_test.py @@ -36,6 +36,6 @@ def test_send_nonascii(self): self.assert_(self.listener.messages == 1, 'should have received 1 message') self.assert_(self.listener.errors == 0, 'should not have received any errors') - (headers, msg) = self.listener.get_latest_message() + (_, msg) = self.listener.get_latest_message() self.assertEquals(stomp.backward.encode(txt), msg) diff --git a/stomp/test/p3_nonascii_test.py b/stomp/test/p3_nonascii_test.py index b7326422..85ad8f04 100644 --- a/stomp/test/p3_nonascii_test.py +++ b/stomp/test/p3_nonascii_test.py @@ -36,7 +36,7 @@ def test_send_nonascii(self): self.assert_(self.listener.messages >= 1, 'should have received 1 message') self.assert_(self.listener.errors == 0, 'should not have received any errors') - (headers, msg) = self.listener.get_latest_message() + (_, msg) = self.listener.get_latest_message() self.assertEquals(stomp.backward.encode(txt), msg) def test_image_send(self): @@ -54,7 +54,7 @@ def test_image_send(self): self.assert_(self.listener.messages >= 1, 'should have received 1 message') self.assert_(self.listener.errors == 0, 'should not have received any errors') - (headers, msg) = self.listener.get_latest_message() + (_, msg) = self.listener.get_latest_message() self.assertEquals(img, msg) open(os.path.join(d, 'test-out.gif'), 'wb').write(img) @@ -87,5 +87,5 @@ def test_send_nonascii_auto_encoding(self): self.assert_(self.listener.messages >= 1, 'should have received 1 message') self.assert_(self.listener.errors == 0, 'should not have received any errors') - (headers, msg) = self.listener.get_latest_message() - self.assertEquals(txt, msg) \ No newline at end of file + (_, msg) = self.listener.get_latest_message() + self.assertEquals(txt, msg) diff --git a/stomp/test/s10_test.py b/stomp/test/s10_test.py index 14da183d..df593a6b 100644 --- a/stomp/test/s10_test.py +++ b/stomp/test/s10_test.py @@ -42,7 +42,7 @@ def testclientack10(self): self.listener.wait_for_message() - (headers, msg) = self.listener.get_latest_message() + (headers, _) = self.listener.get_latest_message() message_id = headers['message-id'] diff --git a/stomp/test/s12_test.py b/stomp/test/s12_test.py index 6ea365b6..e27e1a72 100644 --- a/stomp/test/s12_test.py +++ b/stomp/test/s12_test.py @@ -43,7 +43,7 @@ def testclientack12(self): self.listener.wait_for_message() - (headers, msg) = self.listener.get_latest_message() + (headers, _) = self.listener.get_latest_message() ack_id = headers['ack'] @@ -57,7 +57,7 @@ def testclientnack12(self): self.listener.wait_for_message() - (headers, msg) = self.listener.get_latest_message() + (headers, _) = self.listener.get_latest_message() ack_id = headers['ack'] @@ -98,10 +98,10 @@ def test_specialchars12(self): self.listener.wait_on_receipt() - (headers, msg) = self.listener.get_latest_message() + (headers, _) = self.listener.get_latest_message() - message_id = headers['message-id'] - subscription = headers['subscription'] + _ = headers['message-id'] + _ = headers['subscription'] self.assert_('special-1' in headers) self.assertEqual('test with colon : test', headers['special-1']) self.assert_('special-2' in headers) diff --git a/stomp/test/ss_test.py b/stomp/test/ss_test.py index f09a23aa..5177ceb3 100644 --- a/stomp/test/ss_test.py +++ b/stomp/test/ss_test.py @@ -36,7 +36,7 @@ def test_disconnect(self): server.stop() - for count in range(100): + for _ in range(100): if server.stopped: break time.sleep(0.1) diff --git a/stomp/test/testutils.py b/stomp/test/testutils.py index 4d7c8e02..b5df77f4 100644 --- a/stomp/test/testutils.py +++ b/stomp/test/testutils.py @@ -122,10 +122,10 @@ def add_frame(self, frame): self.frames.append(frame) def run(self): - self.conn, addr = self.s.accept() + self.conn, _ = self.s.accept() while self.running: try: - data = self.conn.recv(1024) + _ = self.conn.recv(1024) frame = self.get_next_frame() if self.conn is None: break diff --git a/stomp/test/threading_test.py b/stomp/test/threading_test.py index d797fb43..1893df6b 100755 --- a/stomp/test/threading_test.py +++ b/stomp/test/threading_test.py @@ -66,7 +66,7 @@ def tearDown(self): break print("Dead threads:", len(errs), "of", self.clients) etype = {} - for ec, ev, tb in errs: + for ec, _, _ in errs: if ec in etype: etype[ec] = etype[ec] + 1 else: diff --git a/stomp/transport.py b/stomp/transport.py index 5b73323b..a633a00c 100644 --- a/stomp/transport.py +++ b/stomp/transport.py @@ -100,7 +100,7 @@ def start(self): """ self.running = True self.attempt_connection() - thread = self.create_thread_fc(self.__receiver_loop) + _ = self.create_thread_fc(self.__receiver_loop) self.notify('connecting') def stop(self): @@ -325,7 +325,6 @@ def __read(self): log.debug("socket read interrupted, restarting") continue except Exception: - _, e, _ = sys.exc_info() c = b'' if len(c) == 0: raise exception.ConnectionClosedException() diff --git a/stomp/utils.py b/stomp/utils.py index 75e12291..4ab97651 100755 --- a/stomp/utils.py +++ b/stomp/utils.py @@ -64,7 +64,7 @@ def is_localhost(host_and_port): Return 1 if the specified host+port is a member of the 'localhost' list of hosts, 2 if not (predominately used as a sort key. """ - (host, port) = host_and_port + (host, _) = host_and_port if host in LOCALHOST_NAMES: return 1 else: