^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Fix spurious readiness flags in some of the wait functions (:ticket:`#1141`).
+- Fix high CPU usage using the ``wait_c`` function on Windows (:ticket:`#645`).
- Fix bad data on error in binary copy (:ticket:`#1147`).
- Don't raise warning, and don't leak resources, if a builtin function is used
as JSON dumper/loader function (:ticket:`#1165`).
}
else {
tv.tv_sec = (int)timeout;
- tv.tv_usec = (int)(((long)timeout * SEC_TO_US) % SEC_TO_US);
+ tv.tv_usec = (int)((long)(timeout * SEC_TO_US) % SEC_TO_US);
tvptr = &tv;
}
assert d == pytest.approx(0.1, 0.05)
+@pytest.mark.slow
+@pytest.mark.parametrize("waitfns", waitfns)
+def test_wait_no_busy_loop(pgconn, waitfns):
+ waitfn = getattr(waiting, waitfns)
+
+ pgconn.send_query(b"select pg_sleep(1)")
+ gen = generators.execute(pgconn)
+ ncalls = 0
+
+ def gen_wrapper():
+ nonlocal ncalls
+ try:
+ for x in gen:
+ res = yield x
+ ncalls += 1
+ gen.send(res)
+ except StopIteration as ex:
+ return ex.value
+
+ (res,) = waitfn(gen_wrapper(), pgconn.socket, 0.3)
+ assert res.status == ExecStatus.TUPLES_OK
+ assert ncalls < 5
+
+
@pytest.mark.slow
@pytest.mark.skipif(
"sys.platform == 'win32'", reason="win32 works ok, but FDs are mysterious"
assert d == pytest.approx(0.1, 0.05)
+@pytest.mark.slow
+@pytest.mark.parametrize("waitfns", waitfns)
+async def test_wait_no_busy_loop(pgconn, waitfns):
+ waitfn = getattr(waiting, waitfns)
+
+ pgconn.send_query(b"select pg_sleep(1)")
+ gen = generators.execute(pgconn)
+ ncalls = 0
+
+ def gen_wrapper():
+ nonlocal ncalls
+ try:
+ for x in gen:
+ res = yield x
+ ncalls += 1
+ gen.send(res)
+ except StopIteration as ex:
+ return ex.value
+
+ (res,) = await waitfn(gen_wrapper(), pgconn.socket, 0.3)
+ assert res.status == ExecStatus.TUPLES_OK
+ assert ncalls < 5
+
+
@pytest.mark.slow
@pytest.mark.skipif(
"sys.platform == 'win32'", reason="win32 works ok, but FDs are mysterious"