Skip to content

Commit 2e161bd

Browse files
authored
Use selectors.DefaultSelector over select.select (#605)
select.select, while being available on many platforms has the drawback of not being very modern. On some Linux systems, for instance, it is limited to 1024 open file descriptors. Python offers a nice wrapper to choose the best way for each OS to poll sockets named selectors.DefaultSelector. Backport of #604
1 parent 6cfd0c6 commit 2e161bd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

neo4j/io/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
)
4141
from logging import getLogger
4242
from random import choice
43-
from select import select
43+
import selectors
4444
from socket import (
4545
AF_INET,
4646
AF_INET6,
@@ -1262,8 +1262,9 @@ def _handshake(s, resolved_address):
12621262

12631263
# Handle the handshake response
12641264
ready_to_read = False
1265-
while not ready_to_read:
1266-
ready_to_read, _, _ = select((s,), (), (), 1)
1265+
with selectors.DefaultSelector() as selector:
1266+
selector.register(s, selectors.EVENT_READ)
1267+
selector.select(1)
12671268
try:
12681269
data = s.recv(4)
12691270
except OSError:

0 commit comments

Comments
 (0)