Skip to content

Commit db28a53

Browse files
domob1812furszy
authored andcommitted
Skip is_closing() check when not available.
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#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#13745.
1 parent be9dacb commit db28a53

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
@@ -181,7 +181,17 @@ def send_message(self, message):
181181
raise IOError('Not connected')
182182
self._log_message("send", message)
183183
tmsg = self._build_message(message)
184-
NetworkThread.network_event_loop.call_soon_threadsafe(lambda: self._transport and not self._transport.is_closing() and self._transport.write(tmsg))
184+
185+
def maybe_write():
186+
if not self._transport:
187+
return
188+
# Python <3.4.4 does not have is_closing, so we have to check for
189+
# its existence explicitly as long as Bitcoin Core supports all
190+
# Python 3.4 versions.
191+
if hasattr(self._transport, 'is_closing') and self._transport.is_closing():
192+
return
193+
self._transport.write(tmsg)
194+
NetworkThread.network_event_loop.call_soon_threadsafe(maybe_write)
185195

186196
# Class utility methods
187197

0 commit comments

Comments
 (0)