From 55d89f972bcf11732b73c4cbc84b5b6812043dda Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Wed, 24 Jun 2026 15:54:15 -0500 Subject: [PATCH] Use `time.sleep(0)` to align with decision in #19871 See https://github.com/element-hq/synapse/pull/19871#discussion_r3462533989 --- tests/server.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/server.py b/tests/server.py index 9488307805..52b7dba749 100644 --- a/tests/server.py +++ b/tests/server.py @@ -334,9 +334,12 @@ class FakeChannel: # could be things spawned on the Twisted reactor threadpool or Tokio thread # pool (async Rust code). # - # We could also use `time.sleep(0)` here but this is more precise - os.sched_yield() - # time.sleep(0) + # Note: Since we're waiting real-time (`timeout` duration), the tests also + # pass with `time.sleep(0)` commented out because Python has a default + # thread switch interval (5ms for cpython) (see + # `sys.setswitchinterval(interval)`). We still want this here as we're able + # to preempt and cause the thread context swtich to happen faster. + time.sleep(0) # Advance the Twisted reactor and run any scheduled callbacks #