Skip to content

Commit

Permalink
Skip is_closing() check when not available.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
domob1812 authored and furszy committed Jun 28, 2021
1 parent be9dacb commit db28a53
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/functional/test_framework/mininode.py
Expand Up @@ -181,7 +181,17 @@ def send_message(self, message):
raise IOError('Not connected')
self._log_message("send", message)
tmsg = self._build_message(message)
NetworkThread.network_event_loop.call_soon_threadsafe(lambda: self._transport and not self._transport.is_closing() and self._transport.write(tmsg))

def maybe_write():
if not self._transport:
return
# Python <3.4.4 does not have is_closing, so we have to check for
# its existence explicitly as long as Bitcoin Core supports all
# Python 3.4 versions.
if hasattr(self._transport, 'is_closing') and self._transport.is_closing():
return
self._transport.write(tmsg)
NetworkThread.network_event_loop.call_soon_threadsafe(maybe_write)

# Class utility methods

Expand Down

0 comments on commit db28a53

Please sign in to comment.