Skip to content

Commit 64b9f27

Browse files
committed
Skip is_closing() check when not available.
bitcoin/bitcoin#13715 introduced a new check for _transport.is_closing() in mininode's P2PConnection's. This function is only available from Python 3.4.4, though, while Bitcoin is supposed to support all Python 3.4 versions. In this change, we make the check conditional on is_closing() being available. If it is not, then we revert to the behaviour before the check was introduced; this means that bitcoin/bitcoin#13579 is not fixed for old systems, but at least the tests work as they used to do before. This includes a small refactoring from a one-line lambda to an inline function, because this makes the code easier to read with more and more conditions being added. Fixes bitcoin/bitcoin#13745.
1 parent c0a47da commit 64b9f27

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/functional/test_framework/mininode.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,17 @@ def send_message(self, message):
179179
raise IOError('Not connected')
180180
self._log_message("send", message)
181181
tmsg = self._build_message(message)
182-
NetworkThread.network_event_loop.call_soon_threadsafe(lambda: self._transport and not self._transport.is_closing() and self._transport.write(tmsg))
182+
183+
def maybe_write():
184+
if not self._transport:
185+
return
186+
# Python <3.4.4 does not have is_closing, so we have to check for
187+
# its existence explicitly as long as Bitcoin Core supports all
188+
# Python 3.4 versions.
189+
if hasattr(self._transport, 'is_closing') and self._transport.is_closing():
190+
return
191+
self._transport.write(tmsg)
192+
NetworkThread.network_event_loop.call_soon_threadsafe(maybe_write)
183193

184194
# Class utility methods
185195

0 commit comments

Comments
 (0)