|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
| 14 | +import sys |
14 | 15 |
|
15 | 16 | from kubernetes.client.rest import ApiException, ApiValueError
|
16 | 17 |
|
@@ -165,8 +166,24 @@ def update(self, timeout=0):
|
165 | 166 | if not self.sock.connected:
|
166 | 167 | self._connected = False
|
167 | 168 | 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 | + |
170 | 187 | if r:
|
171 | 188 | op_code, frame = self.sock.recv_data_frame(True)
|
172 | 189 | if op_code == ABNF.OPCODE_CLOSE:
|
|
0 commit comments