logger = logging.getLogger(__name__)
-def wait_selector(gen: PQGen[RV], fileno: int, interval: float | None = None) -> RV:
+def wait_selector(gen: PQGen[RV], fileno: int, interval: float = 0.0) -> RV:
"""
Wait for a generator using the best strategy available.
`Ready` values when it would block.
:param fileno: the file descriptor to wait on.
:param interval: interval (in seconds) to check for other interrupt, e.g.
- to allow Ctrl-C. If zero or None, wait indefinitely.
+ to allow Ctrl-C.
:return: whatever `!gen` returns on completion.
Consume `!gen`, scheduling `fileno` for completion when it is reported to
block. Once ready again send the ready state back to `!gen`.
"""
+ if interval is None:
+ raise ValueError("indefinite wait not supported anymore")
try:
s = next(gen)
with DefaultSelector() as sel:
return rv
-def wait_conn(gen: PQGenConn[RV], interval: float | None = None) -> RV:
+def wait_conn(gen: PQGenConn[RV], interval: float = 0.0) -> RV:
"""
Wait for a connection generator using the best strategy available.
:param gen: a generator performing database operations and yielding
(fd, `Ready`) pairs when it would block.
:param interval: interval (in seconds) to check for other interrupt, e.g.
- to allow Ctrl-C. If zero or None, wait indefinitely.
+ to allow Ctrl-C.
:return: whatever `!gen` returns on completion.
Behave like in `wait()`, but take the fileno to wait from the generator
itself, which might change during processing.
"""
+ if interval is None:
+ raise ValueError("indefinite wait not supported anymore")
try:
fileno, s = next(gen)
- if not interval:
- interval = None
with DefaultSelector() as sel:
sel.register(fileno, s)
while True:
return rv
-async def wait_async(gen: PQGen[RV], fileno: int, interval: float | None = None) -> RV:
+async def wait_async(gen: PQGen[RV], fileno: int, interval: float = 0.0) -> RV:
"""
Coroutine waiting for a generator to complete.
`Ready` values when it would block.
:param fileno: the file descriptor to wait on.
:param interval: interval (in seconds) to check for other interrupt, e.g.
- to allow Ctrl-C. If None, wait indefinitely.
+ to allow Ctrl-C.
:return: whatever `!gen` returns on completion.
Behave like in `wait()`, but exposing an `asyncio` interface.
"""
+ if interval is None:
+ raise ValueError("indefinite wait not supported anymore")
+
# Use an event to block and restart after the fd state changes.
# Not sure this is the best implementation but it's a start.
ev = Event()
return rv
-async def wait_conn_async(gen: PQGenConn[RV], interval: float | None = None) -> RV:
+async def wait_conn_async(gen: PQGenConn[RV], interval: float = 0.0) -> RV:
"""
Coroutine waiting for a connection generator to complete.
:param gen: a generator performing database operations and yielding
(fd, `Ready`) pairs when it would block.
:param interval: interval (in seconds) to check for other interrupt, e.g.
- to allow Ctrl-C. If zero or None, wait indefinitely.
+ to allow Ctrl-C.
:return: whatever `!gen` returns on completion.
Behave like in `wait()`, but take the fileno to wait from the generator
itself, which might change during processing.
"""
+ if interval is None:
+ raise ValueError("indefinite wait not supported anymore")
+
# Use an event to block and restart after the fd state changes.
# Not sure this is the best implementation but it's a start.
ev = Event()
# Specialised implementation of wait functions.
-def wait_select(gen: PQGen[RV], fileno: int, interval: float | None = None) -> RV:
+def wait_select(gen: PQGen[RV], fileno: int, interval: float = 0.0) -> RV:
"""
Wait for a generator using select where supported.
BUG: on Linux, can't select on FD >= 1024. On Windows it's fine.
"""
+ if interval is None:
+ raise ValueError("indefinite wait not supported anymore")
try:
s = next(gen)
_epoll_evmasks = {}
-def wait_epoll(gen: PQGen[RV], fileno: int, interval: float | None = None) -> RV:
+def wait_epoll(gen: PQGen[RV], fileno: int, interval: float = 0.0) -> RV:
"""
Wait for a generator using epoll where supported.
export PSYCOPG_WAIT_FUNC=wait_epoll
pytest tests/test_concurrency.py::test_concurrent_close
"""
+ if interval is None:
+ raise ValueError("indefinite wait not supported anymore")
try:
s = next(gen)
- if interval is None or interval < 0:
+ if interval < 0:
interval = 0.0
with select.epoll() as epoll:
_poll_evmasks = {}
-def wait_poll(gen: PQGen[RV], fileno: int, interval: float | None = None) -> RV:
+def wait_poll(gen: PQGen[RV], fileno: int, interval: float = 0.0) -> RV:
"""
Wait for a generator using poll where supported.
Parameters are like for `wait()`.
"""
+ if interval is None:
+ raise ValueError("indefinite wait not supported anymore")
try:
s = next(gen)
- if interval is None or interval < 0:
+ if interval < 0:
interval = 0
else:
interval = int(interval * 1000.0)
events = ["R", "W", "RW"]
intervals = [pytest.param({}, id="blank")]
-intervals += [pytest.param({"interval": x}, id=str(x)) for x in [None, 0, 0.2, 10]]
+intervals += [pytest.param({"interval": x}, id=str(x)) for x in [0, 0.2, 10]]
@pytest.mark.parametrize("timeout", intervals)
pgconn.finish()
with pytest.raises(psycopg.OperationalError):
await waiting.wait_async(gen, socket)
+
+
+@pytest.mark.parametrize("waitfn", waitfns)
+def test_wait_timeout_none_unsupported(waitfn):
+ waitfn = getattr(waiting, waitfn)
+
+ def gen():
+ r = yield waiting.Wait.R
+ return r
+
+ with pytest.raises(ValueError):
+ waitfn(gen(), 1, None)