From 303e45b1e50ad6e43b8d19c72d6931b93e6ba8c5 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 19 Oct 2023 11:15:06 -0400 Subject: [PATCH] Expand docs --- src/allmydata/util/cputhreadpool.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/allmydata/util/cputhreadpool.py b/src/allmydata/util/cputhreadpool.py index e8b439eee..5c93e9e30 100644 --- a/src/allmydata/util/cputhreadpool.py +++ b/src/allmydata/util/cputhreadpool.py @@ -54,7 +54,12 @@ _DISABLED = False def defer_to_thread( f: Callable[P, R], *args: P.args, **kwargs: P.kwargs ) -> Deferred[R]: - """Run the function in a thread, return the result as a ``Deferred``.""" + """ + Run the function in a thread, return the result as a ``Deferred``. + + However, if ``disable_thread_pool_for_test()`` was called the function will + be called synchronously inside the current thread. + """ if _DISABLED: return maybeDeferred(f, *args, **kwargs) @@ -65,8 +70,8 @@ def defer_to_thread( def disable_thread_pool_for_test(test: TestCase) -> None: """ - For the duration of the test, calls to C{defer_to_thread} will actually run - synchronously. + For the duration of the test, calls to ``defer_to_thread()`` will actually + run synchronously, which is useful for synchronous unit tests. """ global _DISABLED