Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit ef58a56

Browse files
committed
Use select.poll() for exec on linux/darwin
1 parent 2da2b98 commit ef58a56

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

stream/ws_client.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import sys
1415

1516
from kubernetes.client.rest import ApiException, ApiValueError
1617

@@ -165,8 +166,24 @@ def update(self, timeout=0):
165166
if not self.sock.connected:
166167
self._connected = False
167168
return
168-
r, _, _ = select.select(
169-
(self.sock.sock, ), (), (), timeout)
169+
170+
# The options here are:
171+
# select.select() - this will work on most OS, however, it has a
172+
# limitation of only able to read fd numbers up to 1024.
173+
# i.e. does not scale well. This was the original
174+
# implementation.
175+
# select.poll() - this will work on most unix based OS, but not as
176+
# efficient as epoll. Will work for fd numbers above 1024.
177+
# select.epoll() - newest and most efficient way of polling.
178+
# However, only works on linux.
179+
if sys.platform in ['linux', 'linux2', 'darwin']:
180+
poll = select.poll()
181+
poll.register(self.sock.sock, select.POLLIN)
182+
r = poll.poll(timeout)
183+
else:
184+
r, _, _ = select.select(
185+
(self.sock.sock, ), (), (), timeout)
186+
170187
if r:
171188
op_code, frame = self.sock.recv_data_frame(True)
172189
if op_code == ABNF.OPCODE_CLOSE:

0 commit comments

Comments
 (0)