Skip to content

Commit

Permalink
Implemented has as part of class constructor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
strunker authored Dec 26, 2022
1 parent 94440df commit f0801ce
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pychromecast/socket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit f0801ce

Please sign in to comment.