]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
perf: use wait_select() as even if kqueue is the default
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 25 Oct 2022 16:13:15 +0000 (18:13 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 11 Dec 2022 19:53:20 +0000 (19:53 +0000)
There is a bit less overhead using this simpler function than using
wait_selector.

psycopg/psycopg/waiting.py

index 3fb4cf097d5634ac181a0c4564c184805c9a587e..3b13296495a85e213ceee241e2a0c9511526d8ff 100644 (file)
@@ -240,7 +240,7 @@ def wait_select(gen: PQGen[RV], fileno: int, timeout: Optional[float] = None) ->
                 ready |= READY_W
             if not ready:
                 continue
-            assert s & ready
+            assert s & ready
             s = gen.send(ready)  # type: ignore
 
     except StopIteration as ex:
@@ -290,7 +290,7 @@ def wait_epoll(gen: PQGen[RV], fileno: int, timeout: Optional[float] = None) ->
                     ready = READY_R
                 if ev & ~select.EPOLLIN:
                     ready |= READY_W
-                assert s & ready
+                assert s & ready
                 s = gen.send(ready)
                 evmask = poll_evmasks[s]
                 epoll.modify(fileno, evmask)
@@ -313,10 +313,11 @@ elif selectors.DefaultSelector is getattr(selectors, "EpollSelector", None):
     # NOTE: select seems more performing than epoll. It is admittedly unlikely
     # that a platform has epoll but not select, so maybe we could kill
     # wait_epoll altogether(). More testing to do.
-    if hasattr(selectors, "SelectSelector"):
-        wait = wait_select
-    else:
-        wait = wait_epoll
+    wait = wait_select if hasattr(selectors, "SelectSelector") else wait_epoll
+
+elif selectors.DefaultSelector is getattr(selectors, "KqueueSelector", None):
+    # wait_select is faster than wait_selector, probably because of less overhead
+    wait = wait_select if hasattr(selectors, "SelectSelector") else wait_selector
 
 else:
     wait = wait_selector