From: Daniele Varrazzo Date: Sun, 9 Apr 2023 18:59:55 +0000 (+0200) Subject: fix: don't use select as wait function if possible X-Git-Tag: 3.1.9~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c11db3ebd52c300f0445a721be7971b40e15227;p=thirdparty%2Fpsycopg.git fix: don't use select as wait function if possible select is marginally faster than others, but has the limitation of not allowing FD > 1024, so it is not a good default. If people need performance, they will use wait_c anyway, which is based on poll, and doesn't have the limitation. --- diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py index 7abfc58a9..2c4a10fd1 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -318,14 +318,7 @@ elif selectors.DefaultSelector is getattr(selectors, "SelectSelector", None): wait = wait_select 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. - 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 + wait = wait_epoll else: wait = wait_selector diff --git a/tests/test_waiting.py b/tests/test_waiting.py index f5ece29e5..bcfd348c2 100644 --- a/tests/test_waiting.py +++ b/tests/test_waiting.py @@ -83,9 +83,9 @@ def test_wait_bad(pgconn, waitfn): @pytest.mark.skipif( "sys.platform == 'win32'", reason="win32 works ok, but FDs are mysterious" ) -@pytest.mark.parametrize("waitfn", waitfns) -def test_wait_large_fd(dsn, waitfn): - waitfn = getattr(waiting, waitfn) +@pytest.mark.parametrize("fname", waitfns) +def test_wait_large_fd(dsn, fname): + waitfn = getattr(waiting, fname) files = [] try: @@ -100,7 +100,7 @@ def test_wait_large_fd(dsn, waitfn): assert pgconn.socket > 1024 pgconn.send_query(b"select 1") gen = generators.execute(pgconn) - if waitfn is waiting.wait_select: + if fname == "wait_select": with pytest.raises(ValueError): waitfn(gen, pgconn.socket) else: