From f0801cee753b4cc84638a5a6a0032d3869736edc Mon Sep 17 00:00:00 2001 From: strunker Date: Sun, 25 Dec 2022 20:50:45 -0500 Subject: [PATCH] Implemented has as part of class constructor the hasattr check should take place only once as part of the class constructor, we simply check the object property on any subsequent call to run_once. --- pychromecast/socket_client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pychromecast/socket_client.py b/pychromecast/socket_client.py index 64ec3ca7c..1bf7bb229 100644 --- a/pychromecast/socket_client.py +++ b/pychromecast/socket_client.py @@ -229,6 +229,8 @@ def __init__( self.receiver_controller.register_status_listener(self) + self.hasSelectPoll = hasattr(select,"poll") + def initialize_connection( self, ): # pylint:disable=too-many-statements, too-many-branches @@ -565,9 +567,8 @@ def run_once(self, timeout=POLL_TIME_NON_BLOCKING): # poll the socket, as well as the socketpair to allow us to be interrupted rlist = [self.socket, self.socketpair[0]] - availableCommands = dir(select) try: - if "poll" in availableCommands: + if self.hasSelectPoll == True: # Map file descriptors to socket objects because select.select does not support fd > 1024 # https://stackoverflow.com/questions/14250751/how-to-increase-filedescriptors-range-in-python-select fd_to_socket = {rlist_item.fileno(): rlist_item for rlist_item in rlist}