Skip to content

Commit 08ec53f

Browse files
committed
Use selectors.DefaultSelector over select.select
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.
1 parent 7eb49eb commit 08ec53f

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
@@ -41,7 +41,7 @@
4141
)
4242
from logging import getLogger
4343
from random import choice
44-
from select import select
44+
import selectors
4545
from socket import (
4646
AF_INET,
4747
AF_INET6,
@@ -1326,8 +1326,9 @@ def _handshake(s, resolved_address):
13261326

13271327
# Handle the handshake response
13281328
ready_to_read = False
1329-
while not ready_to_read:
1330-
ready_to_read, _, _ = select((s,), (), (), 1)
1329+
with selectors.DefaultSelector() as selector:
1330+
selector.register(s, selectors.EVENT_READ)
1331+
selector.select(1)
13311332
try:
13321333
data = s.recv(4)
13331334
except OSError:

0 commit comments

Comments
 (0)